Also don’t check every 300ms. The user doesn’t switch apps that fast. It may be enough to check every 2 seconds.
And if it is w, you may be in some state with no front app, e.g. screen saver takes over.
if w ever equals NIL, you have bigger problems to worry about!
The NSWorkspace class should not be possible to be NIL, except maybe a bug in the plugin.
Yes, NSWorkspace notifications will tell you when the user switches applications. For the time being you can get that application info, however I don’t know if this is possible in the App Sandbox or allowed on the Mac App Store, and it may not be possible in the future, you know for security purposes…
I would recommend against that approach, for two reasons.
NSWorkspace Notifications will tell you when the user switches applications, no need for polling or loops. This will have th minimum benefit that it will make your application more energy efficient.
It is entirely possible that w.frontmostapplication may never be valid, at which point your application deadlocks. While I would encourage you to adopt the notifications, if you don’t want to do so, at least add a timeout to the loop, just incase Apple introduce a bug or decide that your application no longer is able to access the front most application information.
I removed the while/wend loop and switched it back to a notification that I’ll remove after more testing. I’ve been using this particular app for about a year or so?
It works with a keyboard remapper. The remapper doesn’t automatically change profiles when you change applications. It does accept terminal commands, so my app sends those commands whenever the frontmost application changes.
I’m pretty sure Apple wouldn’t allow it in the App Store as it only works if you have the remapper. I do plan to sell it online eventually, but it’s such a niche app I’m not even sure it’s beer money.
It does make the comic book work I do in Photoshop and Clip Studio Paint so much faster and easier with the one handed keyboard since I no longer have to manually change profiles when I switch back and forth between apps.