Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 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


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

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)


share|improve this question
Can you include the whole script in your question? – patrix 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
up vote 3 down vote accepted
tell application "System Events" to tell (process 1 where frontmost is true)
    set o to name
        set o to o & ":" & name of window 1
    end try
end tell
share|improve this answer
This will need need assistive access to the executing script – Felipe Sabino Jan 23 '15 at 2:26

This looks like what you are looking for:

set app_name to name of (info for (path to frontmost application))
share|improve this answer
info for has been deprecated in favor of tell app "System Events" to properties of. – user495470 Aug 9 '13 at 8:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.