0

I have a AppleScript that runs from a cron job. The script is:

tell application "System Events"
set frontApp to name of first application process whose frontmost is true
end tell
tell application frontApp
if the (count of windows) is not 0 then
    set window_name to name of front window
end if
end tell

(which I got from https://stackoverflow.com/questions/480866/get-the-title-of-the-current-active-window-document-in-mac-os-x in an example of one of many instances where SO has had the answer to a query ready for me)

I use the script to populate a file like this

l

2013-08-07_20:55:04convert - Linux Command - Unix Command
2013-08-07_20:56:05matlab graph colors.... - Stack Overflow
2013-08-07_20:57:06matlab graph colors.... - Stack Overflow
2013-08-07_20:58:07matlab graph colors.... - Stack Overflow
2013-08-07_20:59:08matlab graph colors.... - Stack Overflow
2013-08-07_21:00:10printing - Save MATLAB figure with different background color - Stack Overflow
2013-08-07_21:01:11matlab graph colors.... - Stack Overflow
2013-08-07_21:02:12Changing matlab b - Stack Overflow
2013-08-07_21:03:162013-08-07_21:04:17/Users/josephreddington/Downloads

to keep track of my time. It works well but I have issues like - all I'm getting from the Apple Script is the title of the window i.e.

matlab graph colors.... - Stack Overflow

Whereas what I'd like is a little more information, like active application (Chrome) in this instance - can someone point me in the direction of either a) how to modify the script so that I get the application name as well as the window title, or b) where I find a handy API that tells me how to do a)

Cheers,

  • Can you include the whole script in your question? – nohillside Aug 8 '13 at 16:46
  • That is the whole script - I've got a wrapper in bash that adds the datestamp and writes to file, but that's it... – Joe Aug 8 '13 at 20:12
  • @Joe. I am doing something similar but the i am a facing a issue wherein when i minimise my active window i keep on getting details of the minimised window. Did you face any such problem with the script ? – bhavya_w Sep 12 '16 at 10:05
3
tell application "System Events" to tell (process 1 where frontmost is true)
    set o to name
    try
        set o to o & ":" & name of window 1
    end try
    o
end tell
  • This will need need assistive access to the executing script – Felipe Sabino Jan 23 '15 at 2:26
0

This looks like what you are looking for:

set app_name to name of (info for (path to frontmost application))
  • 1
    info for has been deprecated in favor of tell app "System Events" to properties of. – Lri Aug 9 '13 at 8:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .