Macos Applescript创建新文件夹

Macos Applescript创建新文件夹,macos,scripting,applescript,Macos,Scripting,Applescript,我想在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 "Ne

我想在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

您可以使用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

您可以使用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

我不知道在AppleScript中运行bash命令是否存在欺骗行为,但您也可以这样做:

do shell script "mkdir '~/Desktop/New Folder'"  
当您需要在子文件夹尚不存在的情况下动态创建子文件夹时,此选项非常有用:

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

我不知道在AppleScript中运行bash命令是否存在欺骗行为,但您也可以这样做:

do shell script "mkdir '~/Desktop/New Folder'"  
当您需要在子文件夹尚不存在的情况下动态创建子文件夹时,此选项非常有用:

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

注意:这可能由于两个原因而失败;
(1)被困在singlequote中的“~”无法解析。
(2)“/New Folder/”中的空格将中断路径

do shell script "mkdir -p '~/Desktop/New Folder/Bleep/Bloop'"
已解决:

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

注意:这可能由于两个原因而失败;
(1)被困在singlequote中的“~”无法解析。
(2)“/New Folder/”中的空格将中断路径

do shell script "mkdir -p '~/Desktop/New Folder/Bleep/Bloop'"
已解决:

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

您可以直接使用applescript脚本,通过模拟击键(“N”和command and shift),这将在桌面或“打开查找器”窗口中创建一个新文件夹

在脚本下面,您可以在脚本编辑器中测试它

tell application "System Events" to tell process "Finder"
    set frontmost to true
    keystroke "N" using {command down, shift down}
end tell
如果在“告诉流程”查找器下添加,则脚本可以工作 “将最前面的设置为true” 哪个给

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

您可以直接使用applescript脚本,通过模拟击键(“N”和command and shift),这将在桌面或“打开查找器”窗口中创建一个新文件夹

在脚本下面,您可以在脚本编辑器中测试它

tell application "System Events" to tell process "Finder"
    set frontmost to true
    keystroke "N" using {command down, shift down}
end tell
如果在“告诉流程”查找器下添加,则脚本可以工作 “将最前面的设置为true” 哪个给

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

如何首先检查某个文件夹(此处:
“新文件夹”
)在路径(此处:
p
)中不存在?我收到错误“Finder出现错误:操作无法完成,因为已经有一个同名项目。”编号-48如何首先检查某个文件夹(此处:
“新文件夹”
)在路径(此处:
p
)上是否不存在?我收到错误“Finder出现错误:操作无法完成,因为已存在具有该名称的项。”编号-48