2010-12-20 118 views
1

我想在苹果脚本中制作一个新的文件夹命令苹果脚本制作新文件夹

为什么剂量这个脚本的工作?

tell application "Finder" 
activate 
end tell 
tell application "System Events" 
tell process "Finder" 
    tell menu bar 1 
     tell menu bar item "File" 
      tell menu "File" 
       click menu item "New folder" 
      end tell 
     end tell 
    end tell 
end tell 
end tell 

回答

22

您可以使用AppleScript更直接地做到这一点:

tell application "Finder" 
    set p to path to desktop -- Or whatever path you want 
    make new folder at p with properties {name:"New Folder"} 
end tell 
1
tell application "Finder" 
activate 
end tell 
tell application "System Events" 
tell process "Finder" 
    tell menu bar 1 
     tell menu bar item "File" 
      tell menu "File" 
       click menu item "new folder" 
      end tell 
     end tell 
    end tell 
end tell 
end tell 

--you capitalize the N in new folder the new folder button is not capped. 
0

我不知道,如果运行bash中AppleScript命令是作弊,但你也可以这样做:

do shell script "mkdir '~/Desktop/New Folder'" 

当你需要在不存在的时候即时创建子文件夹时,这是非常有用的:

do shell script "mkdir -p '~/Desktop/New Folder/Bleep/Bloop'"