Applescript detect new drives - macos

I have an applescript studio application that I use for imaging hard drives. Right now it runs a shell script (diskutil list -plist) to get information about the drives attached to the computer, it then presents this information to the user, and the proper drive to image is selected.
Ideally I would like my application to be able to detect when new devices are plugged in, and prompt the user to image that drive.
I was thinking about running the shell script in a loop and comparing the results to detect if a new device is available, but that seems like that would waste a lot of CPU. Is there someway for applescript to listen to some sort of event and detect that a new device is available?

AppleScript (Studio) is not able to register to any system notification, notifications can only be accomplished in Objective-C.
By the way DiskArbitration.framework is much faster than diskutil.
An alternative could be a folder action or a launchd agent which observes /Volumes.
But it's quite circuitous to pass the information to the main application
Hope this helps

Related

Use different shell based on which device woke the PC?

I'm trying to accomplish the following:
When my PC is woken from sleep with the Steam Controller, it lunches directly into Steam Big Picture Mode, without showing the Windows desktop first.
Ideally I'd like to be able to exit from Steam BPM back into Windows desktop, without having to start explorer.exe manually. So explorer.exe should be running in the background, I think.
Could anybody suggest how I could go about this?
You could attach a script to the wake-up event, then have your script check wake-up source and if it's Steam controller, launch Steam in Big Picture mode.
This is general outline. The burden of implementation, falls on your shoulders.

How to run an Applescript when a mouse is connected?

I have an Applescript that changes my mouse tracking speed that I want to run whenever I connect a mouse to my laptop. How do I do something like this? I was thinking of making it into an application and just clicking it whenever I need it, but I feel like there's a better way to do it.
This answer mentions launchd's ability to detect and launch an app when usb devices are connected. Sounds like what you are after.
Execute an application on Mac OS X when a particular type of USB device is connected?
You can get your specific product is, to use in the plist file, from System Profile->USB
Hope that helps.

Starting my app when USB device connected

I need to starting my app when our USB device connected.
My first attempt at this is a background application that pays attention to when USB devices are plugged in. When it notices our device connected, it calls ShellExecute( ) and starts our application.
This works nicely except in Windows 8. Supposing we're on the "Start" screen in Windows 8. In that situation, the application starts in the background and the start screen remains in front.
I think this is a "focus" problem since what I'm actually hoping to do is "steal focus" from the Start screen.
http://blogs.msdn.com/b/oldnewthing/archive/2009/02/20/9435239.aspx
Since my background application doesn't have focus (the Start screen has focus; besides, my application doesn't have a UI), it can't give focus away to my foreground application.
Let me say that in general, I hate focus stealing. Starting the app the user wants to use is a great help to our users.
How can I fix this problem? Maybe the answer is to programmatically ask the start screen to start my app but I don't see a way to do that:
http://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/9ed23f32-0708-48a8-9ff7-5fce6dbe123f/windows-8-start-screen-api
Maybe I'm approaching this in the wrong way. Suggestions?
You're going about this the wrong way. Although you can write a program to constantly monitor the USB ports to detect when something is connected, there's no need. The OS is already doing that anyway.
Register an Autoplay handler for your device type and class. This is distinct from the old AutoRun feature, which would automatically execute programs found on an inserted file system.
You can begin with an overview of the feature from the November 2001 issue of MSDN Magazine.
Your handler will be a COM DLL. You can register the DLL as a handler, and register the handler with events you want to handle. You can either perform everything in the DLL, or you can put the bulk of the functionality in your application and just use the DLL as a proxy between the OS and your program.

How to put monitor on standby and not let it wake up

I have 3 monitors, but I don't need them all turned on all the time. I can just shut them down with power button, but I want to use their standby mode, like Windows does when we let PC idle for a while - it shuts down monitors, HDD, etc.
But of course, I wanna keep using PC and let just that monitor on standby. Others must remain on and that one doesn't wake up even with me using PC.
Is it possible to do that? It would be great to have a shortcut like Winkey+1, 2, 3 etc to shut down and wake up each monitor.
An existing app with this feature is not likely to exist, but is there a Windows API function that can control monitor state, for each monitor in a MultiMonitor system?
The display control panel applet calls SetDisplayConfig to start or stop forced projection on a particular target
You can probably use MS Detours or some other API hooking tool to inspect the usage pattern of the API while using the applet to adjust display settings.
You'll want to try Display Fusion. You should be able to do what you're asking for using Monitor configurations.
I know I'm late on this but use DDC to control your display. You can easily create hotkeys that send a command via DDC to the display to turn-off. This would be equivalent to turning off the display using the button. Works like a charm for me. The only trick is that DDC command specs vary across monitor manufacturers but its not hard to find the right codes to send with the help of google.
Ready made tools also exist for this; search for anything that is related to DDC or EDID and you should find.
Be aware though that this does not remove the display from Windows which means that apps may find their way onto displays that are off and you will be looking for them.

Logon-type wxpython app

I manage a number of Windows PCs which are used to control equipment. Each computer has a specific program installed which is what people launch to use that equipment. We want to require people to log in before they can access this program.
Currently, I have a wxpython app which just launches that executable when people log in with the correct credentials. However, you can just run the program directly and bypass logging on. I'd like to make a mock logon screen, ie, fullscreen and modal, which only goes away when you log in. Also it should not be able to be bypassed by alt-tab, windows key, etc. How might I accomplish this with wxpython?
There is no full proof way to do this on Windows. You can show a wx.Frame modally using its MakeModal() method. And you can catch EVT_CLOSE and basically veto it it they try to close the frame. However, if they have access to the Task Manager or even Run, they can probably get around the screen. Most users won't be that smart though. You can delete the shortcuts to the apps you want to launch with wx and that will force most normal users to use your login screen. It's only the smart ones who like to troll through the file system who will go around it.

Resources