Applescript 创建新文件夹

发布于 2024-10-08 22:40:59 字数 369 浏览 5 评论 0原文

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

为什么这个脚本不起作用?

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

I Want to make a new Folder command in apple script

Why dosent this script work?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

动次打次papapa 2024-10-15 22:40:59

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

You can do it more directly with 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
甜中书 2024-10-15 22:40:59

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

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

当您需要在子文件夹尚不存在时动态创建子文件夹时,这很有用:

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

I don't know if running bash commands within AppleScript is cheating, but you can also do:

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

Which is useful when you need to create sub folders on-the-fly when they don't exist yet:

do shell script "mkdir -p ~'/Desktop/New Folder/Bleep/Bloop'"  
旧人哭 2024-10-15 22:40:59
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.
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.
夜空下最亮的亮点 2024-10-15 22:40:59

注意:这可能会因两个原因而失败;

(1) '~' 陷入单引号中将无法解析。

(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" 

NOTE: This can fail for two reasons;

(1) '~' trapped in singlequote won't parse.

(2) space in '/New Folder/' will break the path.

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

SOLVED:

do shell script "mkdir -p ~/Desktop/" & quoted form of "New Folder/Bleep/Bloop" 
终陌 2024-10-15 22:40:59
tell application "Finder"
    set thepath to alias "Macintosh HD:Users:JasonMagnuson:Documents:" as text
    make new folder at thepath with properties {name:"nov_archive"}
end tell
tell application "Finder"
    set thepath to alias "Macintosh HD:Users:JasonMagnuson:Documents:" as text
    make new folder at thepath with properties {name:"nov_archive"}
end tell
源来凯始玺欢你 2024-10-15 22:40:59

您可以直接使用 applescript 脚本模拟击键(“N”和 command 和 Shift),这将在桌面上或打开的 Finder 窗口中创建一个新文件夹。

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

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

如果您在“tell process”Finder 下添加,则脚本可以工作
“将最前面设置为 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

You can directly with an applescript script by simulating keystroke on ("N" and command and shift) this will create a new folder on the desktop or in the open Finder window.

Below the script, you can test it in the script editor

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

Your script works if you add under "tell process" Finder "
"set frontmost to true"
Which give

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文