Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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 http://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,

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

2 Answers 2

up vote 2 down vote accepted
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
share|improve this answer

This looks like what you are looking for:

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

Your Answer

 
discard

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.