Depending on the version of OS X you are running, you can use NSWorkspace Notifications from a Cocoa-AppleScript template or an Xcode project.

Thanks. I use 10.8. I don't know anything about Cocoa and only little AppleScripting. How i can put one of those notifications to my AppleScript project created in Xcode or AppleScript Editor? For instance notification when app is launched or hard drive mounted. Thanks

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_

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_

Thanks!!! This is cool.

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.