Applescript - list of running apps?

Discussion in 'Mac Programming' started by dryJ, Jun 5, 2009.

  1. macrumors newbie

    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.
  2. macrumors member

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

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

    Sorry, I forgot to add Applescript to the title :rolleyes: Is there a way of doing this in Applescript? Thanks for your efforts though :)
  4. Moderator emeritus


    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
  5. macrumors 6502a

    or the single-line version:
    tell application "System Events" to get the name of every process whose background only is false
  6. macrumors 65816


    Finder can do something similar.

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

Share This Page