Execute script on wallpaper change event
How do I catch the wallpaper change event and execute a script when the wallpaper changes?
-R
Mac OS X (10.6.2)
Mac OS X (10.6.2)
-(void)applicationActivity:(NSNotification *)notification
{
NSRunningApplication *app = [[notification userInfo] objectForKey:@"NSWorkspaceApplicationKey"];
if(app.localizedName isEqualToString:@"ScreenSaverEngine")
{
// Your code here
}
}
-(void)awakeFromNib
{
[[[NSWorkspace sharedWorkspace] notificationCenter]
addObserver:self
selector:@selector(applicationActivity:)
name:NSWorkspaceDidActivateApplicationNotification
object:nil];
}
with timeout of 0 seconds
tell application "Finder" to set current_pic to desktop picture
global old_pic
on run
tell application "Finder" to set old_pic to desktop picture as alias
end run
on idle
tell application "Finder" to set current_pic to desktop picture as alias
if current_pic is not old_pic then
display dialog "Desktop pattern is different"
set old_pic to current_pic
end if
return 10 -- check again in 10 seconds
end idle
Camelot wrote:
The ObjC solution is neater since it adds a hook into the system to call your code when the system environment changes. Not as clear/legible as AppleScript, of course, but it doesn't offer an even more elegant solution.
global currentdesktoppicture
on run
tell application "Finder" to set currentdesktoppicture to desktop picture
end run
on idle
tell application "Finder"
if currentdesktoppicture ≠desktop picture then
activate
set currentdesktoppicture to desktop picture
display dialog "Desktop Picture changed" giving up after 2
end if
end tell
return 1
end idle
Execute script on wallpaper change event