Jump to content

Recommended Posts

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:install
Configure 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:reload
This tells Hammerspoon to reload the configuration file.

hs:open
This opens the Hammerspoon console to the foreground.

hs:nup
This nudges the current window up.

hs:ndown
This nudges the current window down.

hs:nleft
This nudges the current window to the left.

hs:nright
This nudges the current window to the right.

hs:tcaff
This 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:leftthirds
This moves the current window to the left 1/3 of the screen.

hs:rightthirds
This moves the current window to the right 2/3 of the screen.

 

hs:lefthalf
This moves the current window to the left half of the screen.

hs:righthalf
This moves the current window to the right half of the screen.

 

hs:tophalf
This moves the current window to the top half of the screen.

hs:bottomhalf
This moves the current window to the bottom half of the screen.

hs:fullScreen
This moves the window to the maximum size on the screen.

hs:minimize
This minimizes the current window.

hs:tzoom
This 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:running
This 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:snap
This snaps the current window to the closes grid box area.

hs:setgrid
This 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:command
Type 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:expose
This 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:last
This 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 by raguay.customct

Share this post


Link to post

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.

Share this post


Link to post

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 by cands

Share this post


Link to post

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.

Share this post


Link to post

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.

Share this post


Link to post

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 by cands

Share this post


Link to post

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.

Share this post


Link to post

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.

Share this post


Link to post

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!

Share this post


Link to post

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.

Share this post


Link to post

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.

Share this post


Link to post

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 by dfay

Share this post


Link to post

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.

Share this post


Link to post

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 by cands

Share this post


Link to post

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.

Share this post


Link to post

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.

Share this post


Link to post

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.

...

Screen Shot 2017-01-17 at 14.10.35.png

Edited by sokolik_22

Share this post


Link to post
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).

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...