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

标签 ios bash applescript

    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/

相关文章:

ios - 自定义 UINavigationBar 的外观

bash - 在sh中对字符串的条件赋值

ios - Phonegap 3 ios 项目称为 "HelloWorld"。我该如何改变它?

ios - 新的 Apple Vision API VNTranslationalImageRegistrationRequest

python - 在单个 session 中从 python 运行 bash 命令

macos - 让 applescript 自动点击

objective-c - AppleScript with Mail,回复电子邮件,无法设置内容

bash - 将 bash for 循环与 bash 脚本的嵌入式 applescript 结合使用

ios - 如何禁用 UITextview 选择文本,复制/粘贴 UIMenuController 但仍然有超链接工作[不重复]

regex - bash 正则表达式中的匹配组