PDA

View Full Version : Applescript - list of running apps?




dryJ
Jun 5, 2009, 02:58 PM
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
Jun 5, 2009, 03:30 PM
[[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 (http://theocacao.com/document.page/183))

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

dryJ
Jun 5, 2009, 03:42 PM
Sorry, I forgot to add Applescript to the title :rolleyes: Is there a way of doing this in Applescript? Thanks for your efforts though :)

kainjow
Jun 5, 2009, 03:50 PM
Here's an example
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

larkost
Jun 5, 2009, 04:09 PM
or the single-line version:

tell application "System Events" to get the name of every process whose background only is false

mysterytramp
Jun 5, 2009, 06:35 PM
Finder can do something similar.

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

mt