--- 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
--- 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
本文介绍了一段AppleScript代码,用于自动激活Sparrow应用并执行搜索操作。该脚本首先检查Sparrow是否正在运行,如果已运行则直接进行搜索;若未运行,则先启动Sparrow再执行搜索。通过命令行参数可以指定搜索内容。

4168

被折叠的 条评论
为什么被折叠?



