![]() ![]() I also made some changes to cater to Finder as it has a different path. So I find the path of the application returned, then extract the name on disk from that, and use that to check if the focussed window is of an app I am interested in. “Code”) when you try to get the app name of the focussed window. “Visual Studio Code”) – because that’s what Hammerspoon’s hs.application.launchOrFocus() uses but that’s not the name returned by hs.window.focusedWindow() (e.g. I had to modify it from what I found on SO because the loop I had got going (what I found in the first SO post basically) had the app names as on disk (e.g. this should not happen, but just in caseįor i,shortcut in ipairs(ctrlCmdShortcuts) do If the app is Finder the window count returned is one more than the actual count, so I subtract Let's directly bring the last one to focus every time It seems that this list order changes after one window get focused, A table of zero or more hs.window objects owned by the application. Local appWindows = hs.application.get(focusedWindowAppName):allWindows() Since I have the name already from above, I can use that though It can also take pid or bundle, but that doesn't help here ![]() hs.application.get needs the name as per hs.application:name() and not the name on disk If focusedWindow and appNameOnDisk = app then If already focused, try to find the next window Local appNameOnDisk = string.gsub(appNameOnDisk,"/System/Library/CoreServices/","") Local appNameOnDisk = string.gsub(appNameOnDisk,".app", "") ![]() Local appNameOnDisk = string.gsub(focusedWindowPath,"/Applications/", "") Local focusedWindowPath = focusedWindowApp:path() This gives the path - /Applications/.app Local focusedWindowAppName = focusedWindowApp:name() Get the name of this application this isn't really useful fof us as launchOrFocus needs the app name on disk Local focusedWindowApp = focusedWindow:application() I can get the application it belongs to via the :application() method Output of the above is an hs.window object Local focusedWindow = hs.window.focusedWindow() Local function launchOrFocusOrRotate(app) Thanks to this SO post I found that the following bit of code does it neatly: How can I use Hammerspoon to quickly launch apps? ☺️ There is a way to make it use “C” but it’s a bit of a round-about way, and I felt like the app fights against how I wanted to do things.Īnyway, this post is not about rcmd but Hammerspoon. I can’t, for example, use “C” as in my example above as rcmd defaults to “V”. Yes, I can assign the right cmd key (rcmd) and a key to launch apps – so, for instance, “RCmd+C” to launch Visual Studio Code – but it’s not very flexible. In my initial enthusiasm for it, I bought it from the App Store after giving it a quick try – a decision I regret in retrospect, as it’s not very flexible. It’s a good app, and the developer is very responsive and helpful too. One app I know that can do something like this is rcmd. But if I could just assign a hotkey to launch it, that would be great. Currently, any time I want to lookup a password or use the generator I have to click in the menu bar to launch it. This would also be useful for apps like Bitwarden which very irritatingly don’t have the option for a global hotkey. If I could get this functionality in place for all apps, I could say assign “Ctrl+Cmd+C” for Visual Studio Code, “Ctrl+Cmd+O” for Outlook, and easily switch to that app without “Cmd+Tab”-ing through everything else. Bear, for instance, let’s me assign “Ctrl+Cmd+B” to it so I can press these keys from anywhere and Bear opens up. Sort of having global hotkeys for them, if you know what I mean. I keep switching between apps (nothing new there!) but rather than Cmd+Tab my way through a list of apps I wanted an easy way of going to an app I want. One of the things I wanted to do with it is use is as an app launcher. I never got much time to play with it until this past weekend though. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |