I'm doing an applescript cocoa app and I'd like to run a function as a notification with the name "Finished Downloading" is displayed. The function changes a value displayed in the main window of the cocoa app and the notification is created with a terminal command line.
I've tried to use observers but couldn't really understand how they work so, even if it's probably the right thing to use, I couldn't get it to work.
property NSNotificationCenter : class "NSNotificationCenter"
script AppDelegate
property parent : class "NSObject"
on myFunction()
log "hey"
end myFunction
on applicationWillFinishLaunching_(aNotification)
-- Insert code here to initialize your application before any files are opened
set ws to workspaceClass's sharedWorkspace()
set nc to ws's notificationCenter()
tell nc to addObserver_selector_name_object_(me, "myFunction()", "Finished Downloading", missing value) --tried this
end applicationWillFinishLaunching_
end script
As the notification named "Finished Downloading" is displayed in the top right corner of the monitor this script should run myFunction
Hope for help, thanks. Alex
EDIT: thanks to the answer of Willeke I now verified that it's not possible to accomplish what I was trying to do. See Observe for new System Notifications OSX