读取活动应用程序名称,标题和URL的AppleScript [英] AppleScript that reads active application name, title and URL
问题描述
我需要AppleScript,它在从命令行中午餐时将返回三件事:
I need AppleScript that, when lunched from command line, will return three things:
- 当前活动的应用程序名称;前任. 谷歌浏览器","Safari", 蒸汽","iTunes",原子"等.
- 当前活动的应用程序标题(如果有的话)
- 如果当前活动的应用程序是浏览器,我需要当前的 活动标签的网址
- current active application name; ex. "Google Chrome", "Safari", "Steam", "iTunes", "Atom" ect.
- current active application title, if there is one
- if current active application is a browser, I want the current active tab URL
示例:
- 谷歌浏览器; AppleScript:如何获取失败的Safari选项卡的URL 加载? - 堆栈溢出; https://stackoverflow.com/
- iTunes; iTunes
- iTerm2; 1.节点test.js(休眠)
- Safari,GitHub-rails/rails:Ruby on Rails; https://github.com/rails/rails
- Google Chrome; AppleScript: How to get URL of Safari tab which failed to load? - Stack Overflow; https://stackoverflow.com/
- iTunes; iTunes
- iTerm2; 1. node test.js (sleep)
- Safari, GitHub - rails/rails: Ruby on Rails; https://github.com/rails/rails
我知道有一些类似的问题.关于stackoverflow的答案,但是我无法将它们加在一起以完成所有这些工作.非常感谢帮助.
I know there are some similar questions w. answers here on stackoverflow, but I am not able to pice them together to make all of this work. Would appreciate help much.
推荐答案
我想制作一个脚本,该脚本在后台运行该脚本,以便更好地跟踪自己的时间.这是我想出的:
I wanted to make a script that does exactly this running in the background so that I can better keep track of my time. Here's what I came up with:
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 .
Credit goes to https://apple.stackexchange.com/a/171738 for getting me on the right track.
这篇关于读取活动应用程序名称,标题和URL的AppleScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!