|
|
#1 |
|
Notifications
Now and then i need to write small AppleScript to fix some temporary problem with my computer.
I would like my script to receive notifications even it is taxing. App launched or external disk mounted. How i can do this even it's not recommended. Thanks |
|
|
|
0
|
|
|
#2 |
|
Depending on the version of OS X you are running, you can use NSWorkspace Notifications from a Cocoa-AppleScript template or an Xcode project.
__________________
MacBook Pro / OS X Mountain Lion (10.8.3) / Xcode 4.6 / [various (much) older stuff keeping dust off the shelves] |
|
|
|
0
|
|
|
#3 | |
|
Quote:
|
||
|
|
0
|
|
|
#4 |
|
Well, some knowledge of Cocoa and AppleScript will be needed to tweak things to get the desired result. In Lion and Mountain Lion, the AppleScript Editor includes a Cocoa-AppleScript Applet template in which you can access Cocoa via AppleScriptObjC.
Creating a new template using the following example in the main.scpt file will get notifications when applications launch and volumes are mounted: Code:
property theApps : {"System Preferences"} -- a list of applications to watch for
on run -- example
# add a couple of observers for workspace notifications
tell current application's NSWorkspace's sharedWorkspace's notificationCenter
addObserver_selector_name_object_(me, "appLaunched:", current application's NSWorkspaceDidLaunchApplicationNotification, missing value)
addObserver_selector_name_object_(me, "diskMounted:", current application's NSWorkspaceDidMountNotification, missing value)
end tell
end run
on appLaunched_(aNotification) -- an application was launched
# aNotification's userInfo record contains the name, path, bundle identifier, etc, of the application
# the record also includes an instance of NSRunningApplication that contains various information
set theApplication to (aNotification's userInfo's NSWorkspaceApplicationKey's localizedName()) as text
if theApplication is in theApps then
-- do whatever when a watched application launches
say "a watched application has been launched." -- for testing
end if
end appLaunched_
on diskMounted_(aNotification) -- a disk was mounted
# aNotification's userInfo record contains the name, path, URL, etc, of the volume
set theVolume to (NSWorkspaceVolumeLocalizedNameKey of aNotification's userInfo) as text
if theVolume is "Recovery HD" then return -- skip recovery partition
-- do whatever when a disk is mounted
say "the volume " & quoted form of theVolume & " has been mounted." -- for testing
end diskMounted_
__________________
MacBook Pro / OS X Mountain Lion (10.8.3) / Xcode 4.6 / [various (much) older stuff keeping dust off the shelves] |
|
|
|
0
|
|
|
#5 | |
|
Quote:
There is old app called GURL Watcher which don't work anymore. It logged all URLs that was visited by Safari. What is the name of notification it uses? I try to do something similar. |
||
|
|
0
|
|
|
#6 |
|
|
0
|
|
|
#7 |
|
There isn't a NSWorkspace notification when going to web pages - you might take a look at Parental Controls.
__________________
MacBook Pro / OS X Mountain Lion (10.8.3) / Xcode 4.6 / [various (much) older stuff keeping dust off the shelves] |
|
|
|
0
|
|
|
#8 | |
|
Quote:
How GURL Watcher knows what URL was opened in Safari? There is probably simple way to get this information. Thanks again |
||
|
|
0
|
|
|
#9 |
|
I'm asking again how GURL Watcher knows what URL was opened in Safari? Thanks
|
|
|
|
0
|
|
|
#10 |
|
Maybe it uses a Safari plug-in. You could look for Safari SDK documentation.
|
|
|
|
0
|
|
|
#11 |
|
|
0
|
![]() |
|
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
All times are GMT -5. The time now is 03:49 AM.







Linear Mode
