AppleScript:为什么这个脚本会启动 Safari?
AppleScript: Why does this script launch Safari?
这看起来很简单。 "if (frontApp = "Safari") 然后"执行 Safari 部分。如果不是,则执行 else if 部分 "else if (frontApp = "Google Chrome") then"
当我 Chrome 打开并 运行 这个脚本(在 Automator 工作流程中)时,运行 Chrome 部分没问题,然后继续打开 Safari .
这段代码的哪一部分告诉 Safari 打开,我怎样才能阻止它发生?如果只有 Chrome 打开并且我 运行 在 Chrome 中打开它,我不想也不需要 Safari 打开。
提前致谢...
on run {input, parameters}
tell application "System Events" to set frontApp to name of first process whose frontmost is true
if (frontApp = "Safari") then
using terms from application "Safari"
tell application frontApp to set currentTabUrl to URL of front document
tell application frontApp to set currentTabTitle to name of front document
end using terms from
else if (frontApp = "Google Chrome") then
using terms from application "Google Chrome"
tell application frontApp to set currentTabUrl to URL of active tab of front window
tell application frontApp to set currentTabTitle to title of active tab of front window
end using terms from
else
return "You need a supported browser as your frontmost app"
end if
set myInfo to ("MUSIC - " & currentTabUrl & " - " & currentTabTitle)
return myInfo
结束运行
"using terms from application 'Safari'" 行将在第一次编译时启动应用程序,或者在 运行 脚本打开时首次 运行 启动应用程序。
我建议将 tell 块放在 运行 脚本对象中,除非被调用,否则不会启动:
tell application "System Events" to set frontApp to name of first process whose frontmost is true
if (frontApp = "Safari") then
set currentTabUrl to run script "tell application \"Safari\" to get URL of front document"
set currentTabTitle to run script "tell application \"Safari\" to get name of front document"
else if (frontApp = "Google Chrome") then...
运行 脚本是一个相当昂贵的命令,因此您可以使用此 运行 脚本来稍微优化代码。
set {currentTabTitle, currentTabUrl} to run script "tell application \"Safari\"
tell current tab of its front window
return { name, url }
end tell
end tell"
这看起来很简单。 "if (frontApp = "Safari") 然后"执行 Safari 部分。如果不是,则执行 else if 部分 "else if (frontApp = "Google Chrome") then"
当我 Chrome 打开并 运行 这个脚本(在 Automator 工作流程中)时,运行 Chrome 部分没问题,然后继续打开 Safari .
这段代码的哪一部分告诉 Safari 打开,我怎样才能阻止它发生?如果只有 Chrome 打开并且我 运行 在 Chrome 中打开它,我不想也不需要 Safari 打开。
提前致谢...
on run {input, parameters}
tell application "System Events" to set frontApp to name of first process whose frontmost is true
if (frontApp = "Safari") then
using terms from application "Safari"
tell application frontApp to set currentTabUrl to URL of front document
tell application frontApp to set currentTabTitle to name of front document
end using terms from
else if (frontApp = "Google Chrome") then
using terms from application "Google Chrome"
tell application frontApp to set currentTabUrl to URL of active tab of front window
tell application frontApp to set currentTabTitle to title of active tab of front window
end using terms from
else
return "You need a supported browser as your frontmost app"
end if
set myInfo to ("MUSIC - " & currentTabUrl & " - " & currentTabTitle)
return myInfo
结束运行
"using terms from application 'Safari'" 行将在第一次编译时启动应用程序,或者在 运行 脚本打开时首次 运行 启动应用程序。 我建议将 tell 块放在 运行 脚本对象中,除非被调用,否则不会启动:
tell application "System Events" to set frontApp to name of first process whose frontmost is true
if (frontApp = "Safari") then
set currentTabUrl to run script "tell application \"Safari\" to get URL of front document"
set currentTabTitle to run script "tell application \"Safari\" to get name of front document"
else if (frontApp = "Google Chrome") then...
运行 脚本是一个相当昂贵的命令,因此您可以使用此 运行 脚本来稍微优化代码。
set {currentTabTitle, currentTabUrl} to run script "tell application \"Safari\"
tell current tab of its front window
return { name, url }
end tell
end tell"