Become a MacRumors Supporter for $25/year with no ads, private forums, and more!

Mac Applescript - list of running apps?

dryJ

macrumors newbie
Original poster
Oct 12, 2008
21
0
Me again :cool:

1. How can I go about getting a list of running apps (preferably only the apps that you can see in the Dock, I'm not bothered about background processes)so that I can get a variable to move through this list with a repeat command?

Help much appreciated.
 

isharan

macrumors member
Jun 3, 2009
52
0
Code:
[[NSWorkspace sharedWorkspace] launchedApplications]

will return an array with all the running applications. (ones that show up in the dock)

EDIT: If you're looking for just the names of the application, use this instead: (stolen from theocacoa)

Code:
NSWorkspace * ws = [NSWorkspace sharedWorkspace];
NSArray * apps;
apps = [ws valueForKeyPath:@"launchedApplications.NSApplicationName"];
NSLog (@"%@", apps);
 
Comment

dryJ

macrumors newbie
Original poster
Oct 12, 2008
21
0
Sorry, I forgot to add Applescript to the title :rolleyes: Is there a way of doing this in Applescript? Thanks for your efforts though :)
 
Comment

kainjow

Moderator emeritus
Jun 15, 2000
7,958
6
Here's an example
Code:
tell application "System Events"
    repeat with p in every process
        if background only of p is false then
            display dialog name of p as string
        end if
    end repeat
end tell
 
Comment

larkost

macrumors 6502a
Oct 13, 2007
534
1
or the single-line version:
Code:
tell application "System Events" to get the name of every process whose background only is false
 
Comment

mysterytramp

macrumors 65816
Jul 17, 2008
1,334
3
Maryland
Finder can do something similar.

Code:
tell application "Finder"
	get the name of every process whose visible is true
end tell

mt
 
Comment
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.