Created
May 6, 2016 18:43
-
-
Save kylekyle/a096f9734bd72139200f13ae2f4a5208 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://porkrind.org/missives/calling-applescript-from-ruby/ | |
def osascript(script) | |
system 'osascript', *script.split(/\n/).map { |line| ['-e', line] }.flatten | |
end | |
# http://stackoverflow.com/questions/5292204/macosx-get-foremost-window-title | |
osascript <<-END | |
global frontApp, frontAppName, windowTitle | |
set windowTitle to "" | |
tell application "System Events" | |
set frontApp to first application process whose frontmost is true | |
set frontAppName to name of frontApp | |
tell process frontAppName | |
tell (1st window whose value of attribute "AXMain" is true) | |
set windowTitle to value of attribute "AXTitle" | |
end tell | |
end tell | |
end tell | |
return {frontAppName, windowTitle} | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment