NSWorkspaceDidLaunchApplicationNotification

Discussion in 'Mac Programming' started by nelly22, May 17, 2010.

  1. nelly22 macrumors 6502

    Joined:
    Sep 29, 2009
    #1
    I have NSWorkspaceDidLaunchApplicationNotification question. I have this code and i don't know how to get name of launched app.

    Code:
    script TestingAppDelegate
    	property parent : class "NSObject"
    	property pNSWorkspace : class "NSWorkspace"
    	
    	on awakeFromNib()
    		tell (pNSWorkspace's sharedWorkspace())'s notificationCenter()
    			addObserver_selector_name_object_(me, "app_launching", "NSWorkspaceDidLaunchApplicationNotification", missing value)
    		end tell
    	end awakeFromNib
    	
    	on app_launching()
    		say "launched" --this line works
    		say "launched" & launched_app_name --this fails
    	end app_launching
    
    end script
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    I'm not sure about AppleScript, but in Cocoa terms (which is, I suspect, the way we should be thinking as you are interacting with a Cocoa objects) I would expect that app_launching should take a single argument which is an notification object.

    This is covered in the NSNotificationCenter documentation. The object passed with be a NSNotification. You should be able to get details of the launched application out of the userInfo dictionary.

    I would note that unless you are doing a lot of interacting with other apps that you are not showing us it'd be a lot easier to write this in Objective-C rather than dealing with the clunky bridge from AppleScript...
     
  3. nelly22 thread starter macrumors 6502

    Joined:
    Sep 29, 2009
    #3
    Thanks.

    Your answer for total gibberish to me. :)

    I know nothing about Cocoa/ASOC and i can't figure it out even if i read documentation.

    I agree that it would be better to write it in Objective-C since there is lots of app launches it needs to track, but i can only program in AppleScript.
     
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    Then you need to stop, take about 10 steps back and learn how to understand the object you are using, the specific syntax that you are deploying and so on. You are just going to dig deeper and deeper holes for yourself until you do.
     

Share This Page