Applescript - list of running apps?

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

  1. macrumors newbie

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

    #2
    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);
    
     
  3. macrumors newbie

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

    kainjow

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

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

    mysterytramp

    #6
    Finder can do something similar.

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

Share This Page