Jump to content

Mjolnir Workflow


Recommended Posts

Posted (edited)

This workflow is for running scripts using Mjolnir 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 Mjolnir.

 

First off, download Mjolnir from https://github.com/mjolnir-io/mjolnir.git. That site also tells how to get started. To install the needed modules and configuration file, you will need to run the "mj:install" command. This will also install the cli program called "mjolnir".

 

Once mjolnir and it's cli program is installed, use the "mj:find mjolnir" command to set the path to the executable. After this step is done, all the following commands are available to use.

 

mj:install
This will install some modules that is used in the configuration file for this workflow. It will also install a default configuration file for mjolnir. If you already have one, move it to a temporary location, run this command, and then copy your function to the configuration file. This should be the second command you run to get this workflow running.

 

mj:updateinit

This command just updates the init.lua file to the new one for the workflow. It does not try to update the modules.

 

mj:reload
This tells mjolnir to reload the configuration file.

 

mj:open

This will open the Mjolnir console to the front.

 

mj:nup
This nudges the current window up.

 

mj:ndown
This nudges the current window down.

 

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

 

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

 

mj:tcaff
This toggles system caffenate.

 

mj:leftthirds
This moves the current window to the left 1/3 of the screen.

 

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

 

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

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

 

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

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

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

mj:minimize
This minimizes the current window.

mj: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.

mj: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.
 

mj:snap
This snaps the current window to the closes grid box area.

 

mj: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 "mj:setgrid 0, 0, 1, 1". There is also a hotkey set to this value as an example.

 

mj:command
Type in a command string and it will be sent to Mjolnir directly!

 

mj:ftmove
This puts every window for FoldingText to the left half of the screen.

 

mj:fttoday
This focuses the window with the title "today.txt". That is my todo list for the day.

 

mj: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!

 

mj:last
This will move the last window moved around to it's position and size before the movement. This is a single level return.

 
This workflow is also set up with a Remote page as well. Have fun controlling your windows from your iPad or iPhone.
 
 
Please let me know if you have any issues with this workflow.
 
Version: 2.1
Edited by raguay.customct
  • 3 weeks later...
Posted

Hi,

 

Just made many changes and add ons to the Mjolnir workflow. The Mjolnir program is free and will always be free now. So, have fun!

 

This is the fastest window placement program there is for the Mac and it is very configurable (if you know Lua). The expose a named programs windows is a great example of the power you get with this program. Give it a try. You have to have Lua 5.2 and luarocks installed. Homebrew will do it automatically with "brew install lua" and "brew install luarocks".

 

If you have a problem, just let me know.

Posted

This sounded interesting to me, so I walked through the steps to install Mjolnir/Luarocks and your workflow, but when I run the workflow in debug mode it prints this:

 

ERROR: alfred.workflow.action.script] Code 127: /bin/bash: line 29: -c: command not found

 

Any ideas?

Posted

To use any of the other commands, you have to first do "mj:install" to get the mjolnir command line program installed and the initialization file installed with the components that the other commands use. Then you have to run "mj:find mjolnir" to find where your command line tool is placed. It should be in the /usr/local/bin, but I have seen it get installed in other areas on some systems.

 

After that, all the other commands should work. The message you see is the other scripts not able to find the command line program. The "mj:find" command stores the path to the command in the data workspace for the workflow in the file mjolnir.txt. You can use the awf workflow (http://www.packal.org/workflow/alfred-workflow-builder-quickref) to open that directory easily.

 

If you did run the above two commands already, let me know which keyword you invoked so I can look at that script in particular.

Posted (edited)

Ah - sorry. I overlooked running mj:install, thanks. That appeared to complete successfully. [EDIT: I also ran "mj:find mjolnir", and a popup alerted me that the command had been set in the workflow ] -- but after doing that, I restarted the mjolnir app (which I have in /Applications/Mjolnir.app), and now the lua console pops open with this error :

-- Loading ~/.mjolnir/init.lua
/Users/rarnold/.mjolnir/init.lua:20: module 'mjolnir._asm.hydra.applescript' not found:
no field package.preload['mjolnir._asm.hydra.applescript']
no file '/usr/local/share/lua/5.2/mjolnir/_asm/hydra/applescript.lua'
no file '/usr/local/share/lua/5.2/mjolnir/_asm/hydra/applescript/init.lua'
no file '/usr/local/lib/lua/5.2/mjolnir/_asm/hydra/applescript.lua'
no file '/usr/local/lib/lua/5.2/mjolnir/_asm/hydra/applescript/init.lua'
no file './mjolnir/_asm/hydra/applescript.lua'
no file '/usr/local/lib/lua/5.2/mjolnir/_asm/hydra/applescript.so'
no file '/usr/local/lib/lua/5.2/loadall.so'
no file './mjolnir/_asm/hydra/applescript.so'
no file '/usr/local/lib/lua/5.2/mjolnir.so'
no file '/usr/local/lib/lua/5.2/loadall.so'
no file './mjolnir.so'
stack traceback:
[C]: in function 'require'
/Users/rarnold/.mjolnir/init.lua:20: in main chunk
[C]: in function 'xpcall'
/Applications/Mjolnir.app/Contents/Resources/setup.lua:73: in main chunk

...I thought maybe I needed to install the "mjolnir._asm.hydra" rock, so I ran  "luarocks install mjolnir._asm.hydra", but that produced this error:

 

 

Installing http://rocks.moonscript.org/mjolnir._asm.hydra-0.2-1.macosx-x86_64.rock...
stat: cannot read file system information for ‘%A’: No such file or directory
chmod: invalid mode: ‘  File: "/usr/local/lib/luarocks/rocks/mjolnir._asm.hydra/0.2-1/lua/mjolnir/_asm/hydra/init.lua"’
Try 'chmod --help' for more information.
stat: cannot read file system information for ‘%A’: No such file or directory
chmod: invalid mode: ‘  File: "/usr/local/lib/luarocks/rocks/mjolnir._asm.hydra/0.2-1/lib/mjolnir/_asm/hydra/internal.so"’
Try 'chmod --help' for more information.
Updating manifest for /usr/local/lib/luarocks/rocks

Double Jeopardy!  I'm new to lua, so any further tips are welcomed and appreciated :^)

 

Also - I tried running a few of the window movement commands, and I get the following in Alfred's debug window:

 

INFO: alfred.workflow.input.keyword] Processing output 'alfred.workflow.action.script' with arg ''
[INFO: alfred.workflow.input.keyword] Processing output 'alfred.workflow.action.script' with arg ''
Edited by SmokyBarnable
Posted

Hi,

 

I'm sorry. The owner just recently pulled that module. I will have to remove it from the workflow and reupload. In the meantime, you can open an editor to edit ~/.mjolnir/init.lua and remove the line that says:

 

mjolnir.applescript = require "mjolnir._asm.hydra.applescript"

 

and

 

--

-- Function: applescript
--
-- Description: The passed string is parsed as an
-- applescript script.
--
function applescript(string)
flag, result = mjolnir.applescript.applescript(string)
return(result)
end
 
I will repost here when I get the new version uploaded.
Posted (edited)

OK, I removed the require statement for "mjolnir._asm.hydra.applescript" and re-ran "mj:install" -- and it now appears to be working! Thanks! This looks really cool, I'm excited to dig into mjolnir and lua a bit now ...

Edited by SmokyBarnable
  • 2 months later...
Posted

Hi! Thanks for putting together so many workflows! They look really useful and I'm excited to try them out.

 

I'm working on the Mjolnir one now, but I've had some issues. After running mj:install, the init.lua file was overwritten, but the mjolnir cli tool can't be found. On a side-note, I had to manually install each module and reloading the config, until the pop up with your name appeared. I'd appreciate any help!

 

I'm on a macbook pro retina late 2012 with all updated software and Yosemite. I am using the mjolnir workflow posted on Github: https://github.com/raguay/MyAlfred

After running mj:install, these are the popups that appear: https://www.dropbox.com/s/mv25nw1j2va8noi/mjolnirTroubleshooting.png?dl=0

Posted

Hi, Stop and restart Mjolnir. Then, open the console for Mjolnir and see what it says. The install script copies your original init.lua to mjolnir.org in your home directory. Anything you want in it should be copied back into the init.lua file. The console is opened by the dropdown menu from the menubar icon.

 

If you manually installed each of the modules, then the cli module should be built. To run the "mj:find" command, you have to start typing the name of the cli program. Therefore, typing "mj:find mj" should have the cli program show up. You can look in a terminal to see if it is loaded with "which mjolnir". If that does not show the cli program, then it did not get installed. These two modules make up the cli program:

 

luarocks install --server=http://rocks.moonscript.org mjolnir._asm.ipc
luarocks install --server=http://rocks.moonscript.org mjolnir._asm.ipc.cli

 

Make sure these are installed without warnings and it should be okay.

 

Also, check to make sure your version of Lua is 5.2. Earlier versions do not work and 5.3 has not been tested with it.

Posted

Hi,

 

I just overhauled the expose code to give a list of every running application with one or more window. If an application that has only one open window is selected, then it simply brings it to the forefront. Otherwise, it will show all the windows for that application in a matrix and ask you for the column and row value (zero referenced). It will then put all the windows back to their original location and bring the one selected to the forefront.

 

This requires a reinstall of the init.lua file. But, the original file will be copied to your home directory as init.org.

 

If there is any problems or more functionality you would like to see, just let me know!

Posted

Okay, I just pushed a new update: version 1.9. Two more modules were depressiated, so I removed them. I also added a command to update the init.lua file without trying to re-install the modules. Let me know if you have any issues.

Posted

If you are having problems installing Mjolnir, try out Hammerspoon:  https://github.com/Hammerspoon/hammerspoon/releases/latest

 

It is Mjolnir with everything packed together in one place. No external modules and it only loads extensions as they are used. But, Hammerspoon has the window animations built in and can be slow, but Mjolnir doesn't. That is the largest differences.

 

I will be maintaining both of these workflows. Any new feature of one will be added to the other.

 

The other workflow is here: http://www.alfredforum.com/topic/5334-hammerspoon-workflow/

  • 4 weeks later...
Posted

hey, would it be hard to also add 'mj:lefthalf' and 'mj:righthalf', for when you don't want to do leftthirds and rightthirds? or am i using it wrong? thanks!

Posted

Hi,

 

Sorry, but my Mjolnir application kept dying and I have switched to Hammerspoon. It is the same code base, but done as a all in one package (ie: you do not have to figure out dependencies at all or load other versions of Lua).

 

The Hammerspoon workflow has the two mentioned commands and Alfred Remote added as well. This page is the main thread for it:  http://www.alfredforum.com/topic/5334-hammerspoon-workflow/?hl=hammerspoon

 

BTW: The lua script has the command in it I think: type in an Alfred prompt:

 

mj:command moveLeftHalf()

mj:command moveRightHalf()

 

If you want to stay with this version, let me know and I will try to revive Mjolnir on my system. I will have to take off another program with a conflicting lua install.

Posted

Well, I was able to get it working easy enough. The new Mjolnir workflow is uploaded to Packal and my GitHub account. Both Mjolnir and Hammerspoon now have the exact same functionality. Let me know if you need anything else.

 

 

BTW: Try it with Alfred Remote. Makes handling your windows really nice!

Posted

Problem with getting startet with mjolnir:

 

It says on the getting startet page (step 4):

"Create ~/.mjolnir/init.lua, and at the top, require the modules you installed, e.g. like this:"

I have created a init.lua file with textedit. Where do I have to put it, since .mjolnir is not an allowed name for a folder. It does not exist, or at least, I can't find it. 

So what do I have to do? 

I have no experience with lua and for now I just want to use it with this workflow for alfred.

Posted

Once you have Mjolnir installed (loaded on your hard drive, but not configured) and this workflow installed, run "mj:install". This will create the lua.ini file in the ~/.mjolnir directory and install the modules it uses. Make sure you have a working lua 5.2 interpreter as well. That can be loaded using Home Brew with : brew install lua

 

Or, remove Mjolnir and install Hammerspoon. It is the same program with the right Lua interpreter and modules pre-packaged. My workflow for it is: http://www.alfredforum.com/topic/5334-hammerspoon-workflow/?hl=hammerspoon

 

Problem with getting startet with mjolnir:

 

It says on the getting startet page (step 4):

"Create ~/.mjolnir/init.lua, and at the top, require the modules you installed, e.g. like this:"

I have created a init.lua file with textedit. Where do I have to put it, since .mjolnir is not an allowed name for a folder. It does not exist, or at least, I can't find it. 

So what do I have to do? 

I have no experience with lua and for now I just want to use it with this workflow for alfred.

Posted (edited)

hey thanks for that, righthalf and lefthalf working great with mjolnir. Also good would be tophalf, bottomhalf, fullscreen, maximise respectively, if it's possible. just good to create shortcut keys with left, right, up, down etc.

 

Question - is there any benefit in using hammerspoon over mjolnir (or indeed any disadvantage). mjolnir is working fine for me, but i don't mind switching if you're trying to standardise on a single one...

 

cheers!

Edited by jcricket
Posted

The benefits with Hammerspoon is that you never have to worry about conflicting Lua instances from other programs and installing modules are automatic with Hammerspoon (It packages every known modules in it. So, when there is an update, they are all updated). Also, Hammerspoon only loads the modules in memory when used, but Mjolnir loads all modules into memory at startup based on the lua.ini file.

 

I am trying to keep both workflows equal, but it is slower at getting the updates. I like using any changes for a while first before releasing them to the public.

 

Working on your requests....

Posted

Just added several new functions (mj:tophalf, mj:bottomhalf, mj:fullScreen, mj:tzoom, mj:minimize, and mj:running). All of these have been added to the Remote page as well.

 

I also fixed mj:caffineate to work correctly. You will have to re-install the lua.init file with mj:undateinit.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...