首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将此AppleScript转换为osascript?

如何将此AppleScript转换为osascript?
EN

Stack Overflow用户
提问于 2012-08-14 12:05:03
回答 1查看 1.9K关注 0票数 1

我已经写了一个AppleScript,想把它转换成一个osascript,这样我就可以在启动时使用launchd来运行它。有没有办法将它转换为osascript,或者我必须将整个脚本重写为osascript?如果做不到,是否至少有一种方法可以在终端中将其作为osascript运行?谢谢!

代码语言:javascript
复制
on idle
       tell application "System Events" to ¬
    if exists process "Launchpad" then run script
        tell application "Launchpad"
            delay 0
            tell application "System Events" to keystroke "b" using {control down, option down, command down}
            delay 0
            tell application "System Events" to keystroke "b" using {control down, option down, command down}
            delay 0
            tell application "System Events" to keystroke "b" using {control down, option down, command down}
            delay 0
        end tell
end idle
EN

回答 1

Stack Overflow用户

发布于 2012-08-14 17:21:08

如果您只需要每秒运行一次或频率较低,则可以将其另存为普通脚本:

代码语言:javascript
复制
tell application "System Events"
    if not (exists process "Launchpad") then return
    repeat 3 times
        keystroke "b" using {control down, option down, command down}
    end repeat
end tell

并使用launchd重复运行该脚本:

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN
http://www.apple.com/DTDs/PropertyList-1.0.dtd>
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.stackoverflow.11945633</string>
    <key>ProgramArguments</key>
    <array>
        <string>osascript</string>
        <string>/Users/username/Library/Scripts/script.scpt</string>
    </array>
    <key>StartInterval</key>
    <integer>1</integer>
</dict>
</plist>

必须使用launchctl load ~/Library/LaunchAgents/com.stackoverflow.11945633.plist手动加载属性列表。应用更改需要卸载并加载它。

默认情况下,程序在20秒后发送SIGKILL信号。您可以通过添加ExitTimeOut密钥来覆盖超时。参见man launchd.plist

该脚本实际上并不适用于更改Launchpad背景。Launchpad.app只是一个虚拟的应用程序,当它打开时会立即退出。

如果你只想改变背景样式,你可以用defaults write com.apple.dock springboard-background-filter -int 2; killall Dock来实现。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11945633

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档