【问题标题】:Applescript New Folder Named By Date按日期命名的 Applescript 新文件夹
【发布时间】:2013-11-09 01:21:54
【问题描述】:

所以我是 applescript 的新手,我正在尝试制作一个应用程序,该应用程序将在桌面上创建一个具有当前日期和时间名称的新文件夹。每次我运行它时,都会出现错误,并显示“无法将“11/8/13”转换为类型编号。”请帮助并感谢您的意见和回答!

    tell application "Finder"
        set p to path to desktop
        set d to short date string of (current date)
        set t to time string of (current date)
        set FullDate to d + t
        make new folder at p with properties {name:FullDate}
    end tell

【问题讨论】:

    标签: applescript


    【解决方案1】:

    你在 AppleScript 中使用 & 连接,否则它会认为你在尝试添加数字。

    set p to path to desktop
    set d to short date string of (current date)
    set t to time string of (current date)
    set FullDate to d & space & t
    
    tell application "Finder" to make new folder at p with properties {name:FullDate}
    

    【讨论】:

    • 非常感谢!这正是我想要的!
    • 乐于助人。如果我回答了您的问题,请单击复选标记接受答案,以便其他用户知道问题已解决。
    • 还有一个问题@adayzdone。如果我想将路径设置为“/Users/Jeremy/Desktop/1NF1N1T3 Backup”而不是桌面,我会输入什么?
    • 将 p 设置为(文本形式的桌面路径)和“1NF1N1T3 备份”
    【解决方案2】:

    以下脚本创建(并打开)格式为“YYYY-MM-DD”的新文件夹。它在第一个查找器窗口中创建文件夹,如果没有,则在桌面上。很容易调整。

    tell application "Finder"
        try
            if exists Finder window 1 then
                set thisPath to (the target of the front window) as alias
            else
                set thisPath to (path to desktop)
            end if
        on error
            return
        end try
    end tell
    set x to my the_perfect_datestring()
    if x is not "-ERROR" then
        set fullPath to thisPath & x as text
        tell application "Finder"
            try
                --activate
                if not (exists fullPath) then
                    set y to make new folder at thisPath with properties {name:x}
                end if
                activate
                open y
            end try
        end tell
    end if
    on the_perfect_datestring()
        try
            set cd to (the current date)
            set the_year to year of (cd) as number
            set the_month to month of (cd) as number
            set the_day to day of (cd) as number
            if the_month < 10 then set the_month to "0" & the_month
            if the_day < 10 then set the_day to "0" & the_day
            return ((the_year & "-" & the_month & "-" & the_day) as string)
        on error
            return "-ERROR"
        end try
    end the_perfect_datestring
    

    【讨论】:

      猜你喜欢
      • 2019-02-28
      • 1970-01-01
      • 1970-01-01
      • 2018-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多