raguay.customct Posted January 5, 2015 Share Posted January 5, 2015 (edited) This is a direct port of my Mjolnir Workflow. Installing Hammerspoon is much simpler without any external modules needing to be installed. Everything is internal.This workflow is for running scripts using Hammerspoon to control your windows. This is just a sample of the things that can be done. Follow this layout and you can do many neat things with Hammerspoon.First off, download Hammerspoon from http://www.hammerspoon.org/. Once installed, run the "hs:install" to set the configuration file this workflow expects and reload Hammerspoon. After that, everything should just work.hs:installConfigure Hammerspoon with the configuration file that this workflow needs. The original is backed up into the users home directory as hs.orig. hs:upgrade This will upgrade the hammerspoon configuration file instead of writing the main config file. This will work for all versions newer than version 1.4. hs:reloadThis tells Hammerspoon to reload the configuration file.hs:openThis opens the Hammerspoon console to the foreground.hs:nupThis nudges the current window up.hs:ndownThis nudges the current window down.hs:nleftThis nudges the current window to the left.hs:nrightThis nudges the current window to the right.hs:tcaffThis toggles system caffenate. If the AnyBar workflow and program are installed, then an indicator is shown. If caffenate is active, red "zzz" will be shown. Otherwise, grey "zzz" are shown.hs:leftthirdsThis moves the current window to the left 1/3 of the screen.hs:rightthirdsThis moves the current window to the right 2/3 of the screen. hs:lefthalfThis moves the current window to the left half of the screen.hs:righthalfThis moves the current window to the right half of the screen. hs:tophalfThis moves the current window to the top half of the screen.hs:bottomhalfThis moves the current window to the bottom half of the screen.hs:fullScreenThis moves the window to the maximum size on the screen.hs:minimizeThis minimizes the current window.hs:tzoomThis toggles the system fullscreen on and off for the current window. This moves the window to it's own space taking up the entire screen.hs:runningThis will list all the running apps. You can then just select one to bring it to the front, select with alt key to hide it, select with ctrl key to unhide it, and select with the fn key to close the application. hs:snapThis snaps the current window to the closes grid box area.hs:setgridThis requires you to put the x, y for a starting position in a 3x3 matrix for the current window. Then you give the width and height. Therefore, to move the current window to the upper left most block in a 3x3 matric, you would do "hs:setgrid 0, 0, 1, 1". There is also a hotkey set to this value as an example.hs:commandType in a command string and it will be sent to Hammerspoon directly!There is also an external trigger HammerspoonCommand that will pass whatever is sent in the trigger to Hammerspoon using the command processor as in "hs:command". This gives other workflows or scripts the ability to interact with Hammerspoon through Alfred.hs:exposeThis will list all applications. When an application is selected, it will show all of it's windows in a matrix on the screen and ask the user for the coordinates of the one to show. It will then put all the windows back to their original position and bring the one selected to the foreground. If the application has only one window, it will simply bring it to the front.I also created a hotkey for doing Expose on FoldingText. The user can create more in the same manner. Just be careful to get the name of the application correct!hs:lastThis command undoes the very last window move. This assumes all window movements were done with Hammerspoon and this workflow functions. This workflow is also set up with a Remote page as well. Have fun controlling your windows from your iPad or iPhone. Version: 1.4 Packal: http://www.packal.org/workflow/hammerspoon-workflow GitHub: https://github.com/raguay/MyAlfred Edited June 8, 2015 by raguay.customct Link to comment
raguay.customct Posted January 5, 2015 Author Share Posted January 5, 2015 Just uploaded a fix to the expose mode. It wasn't just bring a single window to the front. It now works. Link to comment
raguay.customct Posted January 29, 2015 Author Share Posted January 29, 2015 Just added two new commands and Alfred Remote. Have fun! Link to comment
WalterBeiter Posted January 30, 2015 Share Posted January 30, 2015 Alfred Remote: Please 2/3 Screen / 1/3 Screen move command.. Link to comment
raguay.customct Posted January 31, 2015 Author Share Posted January 31, 2015 Alfred Remote: Please 2/3 Screen / 1/3 Screen move command.. Added to the latest version on Packal and my GitHub account. Link to comment
raguay.customct Posted January 31, 2015 Author Share Posted January 31, 2015 Also updated hs:caffienate to prevent the display from sleeping as well. Before, it just prevented system sleep and not display sleep. You will have to load and re-run "hs:install" to get the Lua script changes. Link to comment
cands Posted February 1, 2015 Share Posted February 1, 2015 (edited) This seems like a useful workflow but it does not work for me. I've installed Hammerspoon, reloaded and run "hs:install". When I try to move a window etc. I see the following error message in Alfred's debug tool: "[ERROR: alfred.workflow.action.script] /bin/bash: line 29: /usr/local/bin/hs: No such file or directory". I'm on OS X 10.10.2. Edited February 1, 2015 by cands Link to comment
raguay.customct Posted February 2, 2015 Author Share Posted February 2, 2015 This seems like a useful workflow but it does not work for me. I've installed Hammerspoon, reloaded and run "hs:install". When I try to move a window etc. I see the following error message in Alfred's debug tool: "[ERROR: alfred.workflow.action.script] /bin/bash: line 29: /usr/local/bin/hs: No such file or directory". I'm on OS X 10.10.2. I am sorry. My directions were not accurate. Once you run "hs:install", you have to reload Hammerspoon. The new lua.init file that the install script copies directs Hammerspoon to copy the hs command to /usr/local/bin/hs. Therefore, Hammerspoon has to be reloaded to get that to happen. If you have the original version of the workflow, it had problems with that. Make sure you have the latest version of the workflow as well. Link to comment
raguay.customct Posted February 2, 2015 Author Share Posted February 2, 2015 Just added several new functions (hs:tophalf, hs:bottomhalf, hs:fullScreen, hs:tzoom, hs:minimize, and hs:running). All of these have been added to the Remote page as well. I also fixed hs:caffineate to work correctly. You will have to re-install the lua.init file with hs:init. Link to comment
cands Posted February 2, 2015 Share Posted February 2, 2015 (edited) I am sorry. My directions were not accurate. Once you run "hs:install", you have to reload Hammerspoon. The new lua.init file that the install script copies directs Hammerspoon to copy the hs command to /usr/local/bin/hs. Therefore, Hammerspoon has to be reloaded to get that to happen. If you have the original version of the workflow, it had problems with that. Make sure you have the latest version of the workflow as well. Thanks for the info! I've installed the latest version (1.3) of the workflow and followed your updated instructions. Unfortunately it is still not working, I get the same error message as before. Strange, maybe something special with my setup is causing this error. I may try the Mjolnir workflow instead but this seems more convenient. If you have further ideas what's causing the problems with Hammerspoon I appreciate it. Edited February 2, 2015 by cands Link to comment
raguay.customct Posted February 3, 2015 Author Share Posted February 3, 2015 Thanks for the info! I've installed the latest version (1.3) of the workflow and followed your updated instructions. Unfortunately it is still not working, I get the same error message as before. Strange, maybe something special with my setup is causing this error. I may try the Mjolnir workflow instead but this seems more convenient. If you have further ideas what's causing the problems with Hammerspoon I appreciate it. Could you open the Hammerspoon console and post what it says. I suspect your /usr/local/bin directory has the wrong permissions and not allowing Hammerspoon to install. In a terminal, type the following: cp /Applications/Hammerspoon.app/Contents/Resources/extensions/hs/ipc/bin/hs /usr/local/bin If this works, the workflows should start working fine. But, if an error is given, then your permissions for that directory are wrong. On my system, it is rwx on the user, and rx for everyone else. You can check the settings by: ls -l /usr/local Let me know if this helps. BTW: If you are having permissions problems on the /usr/local directories, Mjolnir will be even harder to install and get working. Link to comment
dfay Posted February 3, 2015 Share Posted February 3, 2015 Hammerspoon - what a fascinating tool that I've never heard of before. Potential for use with Alfred Remote seems huge - able to do a lot of what I'd thought of trying to do with AppleScript and Moom and cliclick and various other tools all in one. Thank you for bringing this to the forum. Link to comment
raguay.customct Posted February 3, 2015 Author Share Posted February 3, 2015 Hammerspoon - what a fascinating tool that I've never heard of before. Potential for use with Alfred Remote seems huge - able to do a lot of what I'd thought of trying to do with AppleScript and Moom and cliclick and various other tools all in one. Thank you for bringing this to the forum. I am glad you like it. If there is a functionality that you need, but don't see how to implement it, let me know. Two head are better than one! Link to comment
dfay Posted February 4, 2015 Share Posted February 4, 2015 Well....just tried this and my /usr/local/bin permissions are rwxr-xr-x but I'm getting the same error with hs not being found. hs:install worked, and I restarted Hammerspoon but no luck -- I can view the config file in Hammerspoon. I ran the cp command with sudo and things seem to be working now. Link to comment
raguay.customct Posted February 4, 2015 Author Share Posted February 4, 2015 Well....just tried this and my /usr/local/bin permissions are rwxr-xr-x but I'm getting the same error with hs not being found. hs:install worked, and I restarted Hammerspoon but no luck -- I can view the config file in Hammerspoon. I ran the cp command with sudo and things seem to be working now. From the above, I can deduce that the user ownership for that directory is not you. If sudo can do it and you can not normally, then that directory is owned by a different user. Most likely root. But, if everything is working now, then great. Glad to help. Do you use HomeBrew? This tutorial shows how to install and use it: https://computers.tutsplus.com/tutorials/homebrew-demystified-os-xs-ultimate-package-manager--mac-44884 A side affect of using HomeBrew is that it will fix any permissions problems with your /usr/local directory structure. Plus, it is a great way to get some standard Unix programs. Link to comment
dfay Posted February 4, 2015 Share Posted February 4, 2015 (edited) I've used macports ... but very rarely....never updated it for Yosemite ... so probably easy enough to switch. I'm getting a bit hung up with lua ... dot notation vs. colon notation...getting contents of tables...I've been spoiled by the python console.... Ok...just found hs.inspect() and things are looking a bit easier.... Edited February 4, 2015 by dfay Link to comment
dfay Posted February 4, 2015 Share Posted February 4, 2015 Ok...from what I can tell Hammerspoon only deals with windows, not tabs within tabbed windows (e.g. Safari, Terminal) -- is that right? Link to comment
raguay.customct Posted February 4, 2015 Author Share Posted February 4, 2015 Yes. It is a window manager. To work with tabs of an application, you would have to use AppleScript or JavaScript for automation. You can run AppleScript from Hammerspoon with the hs.applescript module. If you have Dash, the documentation for Hammerspoon is in Dash as well. If not, use the API pages on their website. Dot are to reference parts of a structure. hs is a global variable that is a structure with an element named applescript. Therefore, to reference it you use hs.applescript. The colons are for class member references. When you get a window, it is a class variable, not a structure. Therefore, it members are referenced with a colon. It is confusing the difference between different programming languages. I use quite a variety and it does get hard to track them all. But, some are better for some things, while others are better for other things. Lua is super small. That is why they used it in this type of application. dfay 1 Link to comment
cands Posted February 5, 2015 Share Posted February 5, 2015 (edited) Could you open the Hammerspoon console and post what it says. I suspect your /usr/local/bin directory has the wrong permissions and not allowing Hammerspoon to install. In a terminal, type the following: cp /Applications/Hammerspoon.app/Contents/Resources/extensions/hs/ipc/bin/hs /usr/local/bin If this works, the workflows should start working fine. But, if an error is given, then your permissions for that directory are wrong. On my system, it is rwx on the user, and rx for everyone else. You can check the settings by: ls -l /usr/local Let me know if this helps. BTW: If you are having permissions problems on the /usr/local directories, Mjolnir will be even harder to install and get working. The permissions on the /usr/local directory seem to be the same as for your system, but I used sudo for the cp command as dfay described and now everything is working. Great workflow, thanks! Edited February 5, 2015 by cands Link to comment
raguay.customct Posted June 8, 2015 Author Share Posted June 8, 2015 Hi, I just upgraded the Hammerspoon workflow to have an upgrade option and integration with the AnyBar workflow for the caffienate function. The hs:upgrade command will upgrade all future version without messing with the init.lua file. But, for this, you have to run hs:install to now to create this functionality. The install creates the .hammerspoon/init.lua file with a line to load the alfred.lua file. The hs:upgrade will then only effect the alfred.lua file. If the AnyBar workflow and program are installed, then an indicator is shown. If caffenate is active, red "zzz" will be shown. Otherwise, grey "zzz" are shown. Give it a try and let me know how it works for you. cands 1 Link to comment
raguay.customct Posted June 8, 2015 Author Share Posted June 8, 2015 I forgot to mention: With this update, I will no longer be syncing the Mjolnir workflow with this one. The Mjolnir program is not currently being updated and the applescript running submodule no longer works. Since I am making use of that, the two workflows will no longer be syncronized. I no longer use Mjolnir for these reasons and will only be updating the Hammerspoon workflow going forward. Link to comment
sokolik_22 Posted January 17, 2017 Share Posted January 17, 2017 (edited) Does it work with Alfred 3? After: Hammerspoon/"Reload Config": Unable to start Alfred 2 Alfred 3 is running, so Alfred 2 can't be started. ... Edited January 17, 2017 by sokolik_22 Link to comment
raguay.customct Posted January 17, 2017 Author Share Posted January 17, 2017 58 minutes ago, sokolik_22 said: Does it work with Alfred 3? After: Hammerspoon/"Reload Config": Unable to start Alfred 2 Alfred 3 is running, so Alfred 2 can't be started. ... The workflow works great on Alfred 2 or Alfred 3. The latest version with things for Alfred 3 only can be downloaded from my GitHub account: https://github.com/raguay/MyAlfred/blob/master/Alfred 3/HammerspoonWorkflow.alfredworkflow. It is often easiest to download the whole repo and load the workflow you want to use. I'm not sure which version is on Packal right now (I haven't had time to update it there yet). Link to comment
sokolik_22 Posted January 17, 2017 Share Posted January 17, 2017 All right - the github version is ok. Link to comment
EDALPA Posted March 5, 2017 Share Posted March 5, 2017 Hi, Don't know how to run hs:install Help please. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now