Search Sparrow 之 Alfred 优化代码

本文介绍了一段AppleScript代码,用于自动激活Sparrow应用并执行搜索操作。该脚本首先检查Sparrow是否正在运行,如果已运行则直接进行搜索;若未运行,则先启动Sparrow再执行搜索。通过命令行参数可以指定搜索内容。
--- Idea by Runar Dankel with hufeng
--- code by fireshadow52 @ stackoverflow.com
on run argv --- runs the script with arguments from cmd line
if appIsRunning("Sparrow") then
tell application "Sparrow"
tell application "System Events"
key code 120 ---f2按键
end tell
end tell
else
tell application "System Events"
tell application "Sparrow" to activate
key code 120
end tell
end if
tell application "Sparrow" to activate --- activates sparrow
tell application "System Events"
tell process "Sparrow" --- implying Sparrow is already activated
set prevTIDs to AppleScript's text item delimiters --- "saves" last delimiter
key code 3 using {command down, option down} --- send cmd+alt+F to Sparrow invoking search
---set AppleScript's text item delimiters to space --- makes sure the pasted item is correctlyhu formated
keystroke (every text item of argv) as string --- types out every argument that was enter upon run
set AppleScript's text item delimiters to prevTIDs --- restores delimite
---tell application "System Events"
---end tell
end tell
end tell
end run




on appIsRunning(appName)
tell application "System Events" to (name of processes) contains appName
end appIsRunning
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值