【问题标题】:AppleScript that reads active application name, title and URL读取活动应用程序名称、标题和 URL 的 AppleScript
【发布时间】:2018-07-20 15:43:16
【问题描述】:

我需要 AppleScript,当从命令行启动时,它会返回三件事:

  1. 当前活动的应用程序名称;前任。 “谷歌浏览器”、“Safari”、 “Steam”、“iTunes”、“Atom”等。
  2. 当前活动的应用程序标题,如果有的话
  3. 如果当前活动的应用程序是浏览器,我想要当前的 活动标签网址

例子:

我知道有一些类似的问题 w。在stackoverflow上回答,但我无法将它们组合在一起以完成所有这些工作。非常感谢帮助。

【问题讨论】:

  • 相关:Time Sink是商业软件,用于定期记录当前应用程序和窗口标题并分析结果。但是,它不会跟踪当前 URL。
  • @RoryO'Kane 是的,我已经使用 Time Sink 快一年了。这是..好吧,没关系,特别是考虑到我已经为此支付了 5 美元。使用“标签中的 URL”插件和一些设置过滤器的工作,如果你想跟踪你的焦点,它就可以完成工作。

标签: macos command-line scripting applescript osascript


【解决方案1】:

我想制作一个在后台运行的脚本,这样我就可以更好地跟踪我的时间。这是我想出的:

tell application "System Events"
    set frontmostProcess to first process where it is frontmost
    set appName to name of frontmostProcess
end tell
tell application appName
    set windowName to the name of the front window
end tell
if appName is equal to "Safari" then
    tell application "Safari"
        set theURL to the URL of the current tab of the front window
    end tell
else if appName is equal to "Google Chrome" then
    tell application "Google Chrome"
        set theURL to the URL of the active tab of the front window
    end tell
else
    set theURL to ""
end if

return (appName, windowName, theURL)

感谢 https://apple.stackexchange.com/a/171738 让我走上正轨。

【讨论】:

  • 如果应用程序不可编写脚本,此脚本将失败:tell application AppName to set windowName to the name of the front window 不适用于不可编写脚本的应用程序。
猜你喜欢
  • 2013-06-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-01
  • 2011-04-21
  • 2011-01-13
相关资源
最近更新 更多