Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

nelly22

macrumors 6502
Original poster
Sep 29, 2009
366
5
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
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
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...
 

nelly22

macrumors 6502
Original poster
Sep 29, 2009
366
5
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...

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.
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
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.

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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.