|
|
#1 |
|
Run script on Screen Lock
Hey guys,
I want the application TeamViewer to start when I Lock my Imac trough either the key chain way or using the hot corner method. And quit again upon unlocking. Does anyone know how to code the ways, mentioned above, of locking the screen? I couldn't find anything on the web. I am fine with using either a bash script of using apple script. Any help would be appreciated. Last edited by Switch46; Nov 23, 2012 at 08:39 PM. Reason: Clarifying |
|
|
|
0
|
|
|
#2 |
|
Check out Digital Sentry
|
|
|
|
0
|
|
|
#3 | |
|
Quote:
|
||
|
|
0
|
|
|
#4 |
|
I'm looking at the document for the NSWorkspace class. It seems you can ask for notifications when applications launch. I wonder if there's a notification when the screen lock "application" launches. Not sure.
Don't know how you'd get that from a script though. I'm not that familiar with AppleScript. Maybe it can do it. Oh, and there is a "NSWorkspaceScreensDidSleepNotification" and "NSWorkspaceScreensDidWakeNotification". That may be what you want. |
|
|
|
0
|
|
|
#5 |
|
Ok, I played with this a little bit. I used the NSWorkspace notificationCenter to get notifications. The "NSWorkspaceScreensDidSleepNotification" will fire when the screen sleeps (ie., power off). In order to see when the screen saver starts, I asked for the NSWorkspaceDidActivateApplicationNotification. When the screen saver became active, the application name I got was "ScreenSaverEngine". The only thing that was a little goofy was that when the screen saver turns off, the ScreenSaverEngine activates again before moving onto the next application.
You could work with this a bit to launch a script when the Screen Saver launches. Code:
- (void)registerForNotifications
{
[[[NSWorkspace sharedWorkspace] notificationCenter]
addObserver:self
selector:@selector(mScreensSleep:)
name:NSWorkspaceScreensDidSleepNotification
object:nil];
[[[NSWorkspace sharedWorkspace] notificationCenter]
addObserver:self
selector:@selector(mScreensWake:)
name:NSWorkspaceScreensDidWakeNotification
object:nil];
[[[NSWorkspace sharedWorkspace] notificationCenter]
addObserver:self
selector:@selector(mAppLaunch:)
name:NSWorkspaceDidActivateApplicationNotification
object:nil];
}
- (void)mScreensSleep:(NSNotification *)notification
{
NSLog(@"got sleep notification");
}
- (void)mScreensWake:(NSNotification *)notification
{
NSLog(@"got wake notification");
}
- (void)mAppLaunch:(NSNotification *)notification
{
NSRunningApplication *runApp = [[notification userInfo]
objectForKey:NSWorkspaceApplicationKey];
NSLog(@"got app launch %@", runApp.localizedName);
}
|
|
|
|
0
|
|
|
#6 |
|
Thank you very much, I should be able to get it running around this. I didn't expect this much of an effort. Thanks again
|
|
|
|
0
|
|
|
#7 |
|
I don't know what language you are comfortable doing your implementation in. But there's another thread called "Notifications" which shows how to watch these types of notifications in AppleScript instead of Objective-C if you are more comfortable with that.
As for a Cocoa/Obj-C version, if I were going to implement this completely I would probably code is as a "Status Bar" app. |
|
|
|
0
|
|
|
#8 |
|
I am going to go for objective-c, the status bar app seems like a rather good idea. As this is a bit of a pet project and as I am rather new to programming(C++ and Pascal) it will take a while but I'll let you know if it worked out.
Last edited by Switch46; Nov 26, 2012 at 02:41 PM. |
|
|
|
0
|
![]() |
|
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
All times are GMT -5. The time now is 07:51 PM.







Linear Mode
