Applescript для создания новой папки - PullRequest
1 голос
/ 20 декабря 2010

Я хочу создать новую команду папки в сценарии Apple

Почему этот сценарий не работает?

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

Ответы [ 5 ]

24 голосов
/ 20 декабря 2010

Вы можете сделать это более напрямую с 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 голос
/ 08 января 2017

Я не знаю, обманывает ли выполнение команд bash в AppleScript, но вы также можете сделать:

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

Это полезно, когда вам нужно создавать подпапки на лету, когда ониеще не существует:

do shell script "mkdir -p '~/Desktop/New Folder/Bleep/Bloop'"  
1 голос
/ 04 марта 2011
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 голосов
/ 26 февраля 2019

Вы можете напрямую с помощью сценария яблочного сценария, имитируя нажатие клавиш («N» и команду и смещение), создать новую папку на рабочем столе или в открытом окне Finder.

Ниже скрипта вы можете проверить его в редакторе скриптов

tell application "System Events" to tell process "Finder"
    set frontmost to true
    keystroke "N" using {command down, shift down}
end tell

Ваш скрипт работает, если вы добавляете в "сказать процесс" Finder " "установить передний на истину" Которые дают

tell application "System Events"
    tell process "Finder"
        set frontmost to true
                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
0 голосов
/ 15 февраля 2019

ПРИМЕЧАНИЕ. Это может не получиться по двум причинам;
(1) '~' в одиночной кавычке не будет разбираться.
(2) пробел в '/ Новая папка /' будет нарушать путь.

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

РЕШИТЬ:

do shell script "mkdir -p ~/Desktop/" & quoted form of "New Folder/Bleep/Bloop" 
...