2010-12-20 158 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'"