gpt4 book ai didi

ios - 如何从终端(osascript)设置文件夹操作?

转载 作者:行者123 更新时间:2023-11-28 23:56:06 26 4
gpt4 key购买 nike

    set thisFolder to (choose folder with prompt "Choose the folder to which you want to attach the action." default location (path to desktop))
set thisScript to (choose file with prompt "Choose the action you want to attach to the folder." )

tell application "System Events"
set folder actions enabled to true
-- Only one 'folder action' can be attached to any one folder at any one time, but each may contain one or more 'scripts'. It's the scripts' folder action handlers which are triggered, not the scripts themselves. So a single script may contain different handlers for different triggers or you can have several scripts.
-- The folder path specified when creating an action can currently be either an HFS path or a POSIX path, BUT the value actually set is a POSIX path without a trailing slash — which is revelant for any script which may test folder action 'path' values.
set thisAction to (make new folder action at end of folder actions with properties {path:(POSIX path of thisFolder)})
-- Only the script's name is specified as it's assumed to be in one of the (~)/Library/Scripts/Folder Action Scripts/ folders.
make new script at end of thisAction's scripts with properties {name:(get thisScript's name)}
end tell

当我尝试运行它时它工作正常,直到最后一行“make new script ...”然后它失败并显示 -1000 代码

script.scpt:357:450: execution error: System Events got an error: AppleEvent handler failed (-10000)

我要附加的脚本如下:

on adding folder items to this_folder after receiving added_items
display dialog "added"
end adding folder items to

我在这里做错了什么?

谢谢你的时间

最佳答案

附加文件夹操作的语法不久前已更改。 “附加操作”已被弃用,现在使用“make”。正确的语法如下:

set thisFolder to (choose folder with prompt "select folder")
set thisScript to (choose file with prompt "Select script to attach")

tell application "Finder" to set ScripName to name of thisScript
set ScriptPath to POSIX path of thisScript

tell application "System Events"
set thisAction to (make new folder action at end of folder actions with properties {path:(POSIX path of thisFolder)})
tell thisAction to make new script at end of scripts with properties {name:ScripName, POSIX path:ScriptPath}
end tell

警告:如果此文件夹已设置为操作(即使现在附加了脚本),则创建新文件夹操作(第一条指令)将失败。因此,在测试时,要么将其放在 try/end try block 中,要么每次测试该脚本时都必须删除该文件夹的操作。

关于ios - 如何从终端(osascript)设置文件夹操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51233182/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com