INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Hot keys and workflows with MC and Mac  (Read 3058 times)

blgentry

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 8009
Hot keys and workflows with MC and Mac
« on: December 15, 2021, 12:54:39 pm »

I spent a bit of this morning messing around with an Alfred workflow for MC.  My first goal was this:

Assign a keyboard shortcut that would lock my screen and pause MC if it was playing.

Alfred makes hotkey assignment easy.  It also knows how to lock the screen, so that part was easy.  A super duper easy little Alfred workflow (my first one I've ever done) and that worked.  But how to Pause MC?  I tried AppleScript and it was mostly a no go.  Sending specific control keys to MC *did* work via AppleScript.  But it wasn't all that pretty.

Then I remember MCWS, the web based REST API that controls most of what MC can do (not everything, but it does a lot).  I was quickly able to find and test Stop, Play, and Pause.  It took some experimentation, but I found combinations of commands that would Play if stopped OR toggle pause if stopped.  Also found how to do a pure Pause.  It pauses if music is playing.  But does nothing if music is NOT playing.  This is important because if I invoke a pause toggle when locking the screen, it might turn music ON instead of OFF.  A pure pause prevents it from turning it ON ever.  It only pauses.

I wrote some tiny little shell scripts to call MCWS commands with curl (command line web utility that's standard in Mac OS (and many other OSes)).  They worked as expected.

Then I added the pure pause to my lock workflow.  It works!!  Now when I press Command-L, the music stops and my screen instantly goes to screen lock. 

I've never really liked media keys for music control because they aren't in places that are intuitive for me to reach.  So I decided to try a Pause Toggle on a key I could easily remember and reach.  Made a tiny Alfred Workflow for that and *boom* I have a global keyboard shortcut for MC play/pause.  Did another one for next track.  That works great too.

I don't think anyone is really very interested in this, but I'd share more details on the off chance that someone wanted to do something similar.

Brian.
Logged

bob

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 13599
Re: Hot keys and workflows with MC and Mac
« Reply #1 on: December 16, 2021, 10:02:24 am »

You should also be able to send the MCC commands with Launcher which provides the equivalent of the mc28 stub on linux and the MC28.exe stub on windows.
The Launcher executable is:
/Applications/Media Center 28.app/Contents/MacOS/Launcher.app/Contents/MacOS/Launcher
Logged

blgentry

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 8009
Re: Hot keys and workflows with MC and Mac
« Reply #2 on: December 16, 2021, 04:06:14 pm »

Interesting.  I had to use a slightly different path.

Code: [Select]
/Applications/Media\ Center\ 28.app/Contents/MacOS/Launcher.app/Contents/MacOS/Launcher
But once I did, it worked as expected.  I did
Code: [Select]
/command pause and it played/paused MC.  I might retool my scripts to use this as it's a good bit more straightforard.

Thanks.  :)

Brian.
Logged

bob

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 13599
Re: Hot keys and workflows with MC and Mac
« Reply #3 on: December 16, 2021, 04:48:55 pm »

Interesting.  I had to use a slightly different path.

Code: [Select]
/Applications/Media\ Center\ 28.app/Contents/MacOS/Launcher.app/Contents/MacOS/Launcher
But once I did, it worked as expected.  I did
Code: [Select]
/command pause and it played/paused MC.  I might retool my scripts to use this as it's a good bit more straightforward.

Thanks.  :)

Brian.
Yeah, I should have thrown in the backslashes.
Glad it worked for you!
Logged

blgentry

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 8009
Re: Hot keys and workflows with MC and Mac
« Reply #4 on: December 16, 2021, 05:43:14 pm »

It was the ".app" in the middle that threw the path off on my system.

But the bigger issue is I can't seem to make any MCC commands work.  For example, /MCC 10000.  Or more importantly, /MCC 10022,1 , which does a "set pause".  That's important for my application because it's not a toggle.  It's a one way pause.

Since I can't get any MCC command to respond via this launcher,  I think I'll stick with MCWS for now.

Brian.
Logged

bob

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 13599
Re: Hot keys and workflows with MC and Mac
« Reply #5 on: December 16, 2021, 06:35:03 pm »

It was the ".app" in the middle that threw the path off on my system.

But the bigger issue is I can't seem to make any MCC commands work.  For example, /MCC 10000.  Or more importantly, /MCC 10022,1 , which does a "set pause".  That's important for my application because it's not a toggle.  It's a one way pause.

Since I can't get any MCC command to respond via this launcher,  I think I'll stick with MCWS for now.

Brian.
I'll take a look at that, it's possible I missed those.
Logged

bob

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 13599
Re: Hot keys and workflows with MC and Mac
« Reply #6 on: December 17, 2021, 11:05:30 am »

I'll take a look at that, it's possible I missed those.
Yeah, that was a simple fix. I'll get it into a beta build if I can get one other issue resolved today.
Logged

blgentry

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 8009
Re: Hot keys and workflows with MC and Mac
« Reply #7 on: December 18, 2021, 08:38:09 am »

Just downloaded and installed .97 .  The /MCC commands that I have tried all work.  Thanks Mr. Bob!

Brian.
Logged

blgentry

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 8009
Re: Hot keys and workflows with MC and Mac
« Reply #8 on: December 18, 2021, 08:50:20 am »

I just spent 5 extra minutes and ginned up an Alfred workflow for Play/Pause, Next Track, and Previous Track.  Assigned them to some function keys that I like.  I'll probably go ahead and do the same thing for my work computer with it's more sophisticated workflow of locking the screen and pausing the music at the same time.

Thanks again.

Brian.
Logged

bob

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 13599
Re: Hot keys and workflows with MC and Mac
« Reply #9 on: December 19, 2021, 10:21:53 am »

 :) You're welcome. Thanks for pointing out the MCC commands weren't working.
Logged

LilyAarseth

  • World Citizen
  • ***
  • Posts: 156
Re: Hot keys and workflows with MC and Mac
« Reply #10 on: December 23, 2021, 09:55:22 am »

I have very little to no experience with code and stuff, what would a command telling MC to stop playback look like inside a .lua script runtime like hammerspoon?
Logged

blgentry

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 8009
Re: Hot keys and workflows with MC and Mac
« Reply #11 on: December 23, 2021, 06:15:39 pm »

I've never touched hammerspoon.  But I just spend 3 minutes looking up an example or two.  I know almost nothing.  But this looks like what you would use to execute a command line.  Something like:

Code: [Select]
hs.execute("/Applications/Media\ Center\ 28.app/Contents/MacOS/Launcher.app/Contents/MacOS/Launcher /stop", true)
The "/stop" is the command being sent to MC.  Others include /play, /pause, etc.

I hope that gets you started.
Brian.
Logged

LilyAarseth

  • World Citizen
  • ***
  • Posts: 156
Re: Hot keys and workflows with MC and Mac
« Reply #12 on: December 24, 2021, 08:35:35 am »

It crashed the script with your path but by changing the path to the same as bob it stopped crashing,  but no matter what command i try to add it doesn't seem to do anything, hotkey is being assigned according to the log

Quote
hs.hotkey.bind({}, "F6", function()
hs.execute("/Applications/Media Center 28.app/Contents/MacOS/Launcher/Contents/MacOS/Launcher / stop", true)
end)
Logged

bob

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 13599
Re: Hot keys and workflows with MC and Mac
« Reply #13 on: December 24, 2021, 08:40:08 am »

It crashed the script with your path but by changing the path to the same as bob it stopped crashing,  but no matter what command i try to add it doesn't seem to do anything, hotkey is being assigned according to the log
Are you running build 97?
Your entry has a space between / and stop. There cannot be a space there. It's a command line arg.
Logged

LilyAarseth

  • World Citizen
  • ***
  • Posts: 156
Re: Hot keys and workflows with MC and Mac
« Reply #14 on: December 24, 2021, 08:49:53 am »

Yeah I'm on .97. Removed the space and still nothing is happening
Logged

bob

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 13599
Re: Hot keys and workflows with MC and Mac
« Reply #15 on: December 24, 2021, 09:08:15 am »

Yeah I'm on .97. Removed the space and still nothing is happening
I don't know lua but the command line with the backslashed spaces in the Path only (like in Brian's example), looks like it should work.
What crashes? MC or the script?
If it's the script there is something wrong with the script or the interpreter that's running it.

Logged

LilyAarseth

  • World Citizen
  • ***
  • Posts: 156
Re: Hot keys and workflows with MC and Mac
« Reply #16 on: December 24, 2021, 05:17:10 pm »

When using the normal path, like yours bob, I don't get any errors from the .lua and the hotkey is loading now but nothing is happening no matter how many combinations of /stop or even MCC number + decimal + 0 commands i try, there isn't any detailed log to see what is not working because hammerspoon says everything is fine like the other code lines i have in the script to control my preamp via http


edit: by changing the path we managed to go from error 127 to 126 but either hammerspoon doesn't have permissions or i'm overlooking something.

A friend tried to help me all night and despite being contradictory to what you guys said about the path we think this is the path that needs to be used for hammerspoon to reach the launcher: /Applications/MediaCenter28.app/Contents/MacOS/Launcher.app

we also tried a combination of both command stop, stop and the mcc number codes from the wiki but all gives error 126 which according to google points to permission or found but unable to execute or something. i did try to run hammerspoon in root but it didn't seem to want to do that and terminal said it couldn't so we gave up on that also, but maybe i did something wrong.
Logged

blgentry

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 8009
Re: Hot keys and workflows with MC and Mac
« Reply #17 on: December 25, 2021, 05:58:11 am »

Try cutting and pasting your command into Terminal.  Something like:

/Applications/Media Center 28.app/Contents/MacOS/Launcher/Contents/MacOS/Launcher

You should get "No such file or directory".  Meaning that path does not exist.  If you change it to include ".app" on the first launcher part then it should return some text without an overt error.  Like:

Code: [Select]
"/Applications/Media Center 28.app/Contents/MacOS/Launcher.app/Contents/MacOS/Launcher"
Notice the double quotes.  These protect the spaces in the path from the shell.  The code above, pasted into Terminal, won't return an error, but it won't do anything either.  That's because there's no command for it to do.  Now, add a command:

Code: [Select]
"/Applications/Media Center 28.app/Contents/MacOS/Launcher.app/Contents/MacOS/Launcher" /play
That should make MC28 play whatever is in Playing Now.  If that works from Terminal, then you have the command line correct.  If not, then something else is going on.  You need to get the command correct first, and then put it into your Lua script.

Good luck!
Brian.
Logged

LilyAarseth

  • World Citizen
  • ***
  • Posts: 156
Re: Hot keys and workflows with MC and Mac
« Reply #18 on: December 25, 2021, 08:51:47 am »

THANK YOU SO MUCH!


Being able to stop playback on macros without having to manually press the stop button inside the MC window itself was one of the biggest quality of life improvements I ever dreamed of and the biggest issue going from windows to mac with mc. Especially since my previous keyboard, while having a dedicated stop button that worked in mc windows just fine didn't work when i switched to macros in december last year. For some reason there is no media key for stop anymore in the mac ecosystem from what i can tell.


Appreciate both of you taking your time to help me out and help me get it working after so much trial and errors and trying to find ways for it to work over the last year. This made my day!


For anyone else who might be looking for something similar, this is the code i use in hammerspoon now

hs.hotkey.bind({}, "F10", function()
hs.execute("/Applications/MediaCenter28.app/Contents/MacOS/Launcher.app/Contents/MacOS/Launcher /mcc 10002,0", false)
end)
(renamed mc to remove spaces for easier path)


Next project will be figuring out how to translate volume up and down media keys into other keyboard strokes, or maybe mc can translate media keys as well? Example I press volume up media key on my keyboard and then mc translates it into let's say F11 and forwards it and hammerspoon has it keybinded and running my code and increases volume of my amplifier over the network with the actual volume knob on my keyboard instead of the F-keys, that would be pretty cool but i doubt mc can do anything like this?
Logged

bob

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 13599
Re: Hot keys and workflows with MC and Mac
« Reply #19 on: December 25, 2021, 12:08:59 pm »

You might run into issues removing the spaces from MC's application path like you did.

If you do run into issues, rename it back the way it was and add a symlink to the original in the /Applications directory.

sudo -s
cd /Applications
ln -s "Media Center 28.app" MediaCenter28.app
Logged

LilyAarseth

  • World Citizen
  • ***
  • Posts: 156
Re: Hot keys and workflows with MC and Mac
« Reply #20 on: December 27, 2021, 05:25:47 am »

Thanks for the heads up, will save that command in case i need to use it. So far nothing has seemed out of the ordinary after renaming, media server, connecting to remote library, playing to mc from jremote etc, all seems to work :)
Logged

bob

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 13599
Re: Hot keys and workflows with MC and Mac
« Reply #21 on: December 27, 2021, 04:20:16 pm »

Thanks for the heads up, will save that command in case i need to use it. So far nothing has seemed out of the ordinary after renaming, media server, connecting to remote library, playing to mc from jremote etc, all seems to work :)
That's good.
When you update it though, it will re-create that original directory and you'll have to rename it again or switch to the symlink method.
Logged

blgentry

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 8009
Re: Hot keys and workflows with MC and Mac
« Reply #22 on: January 06, 2022, 12:44:28 pm »

Just downloaded and installed .97 .  The /MCC commands that I have tried all work.  Thanks Mr. Bob!

I spent a few minutes this morning/afternoon reworking my Alfred workflow for MC control on my work computer.  This one has a workflow to pause MC and do a screen lock with a single hot key.  This is very convenient.

However, when I used "/pause" as a command line argument to the launcher, it would toggle pause.  So if music was stopped and I locked my screen (with the hot key), then it would PLAY music and then lock.  Hilarious.  :)

Luckily I already knew that there was an MCC command to explicitly pause, even if already paused.  A "true pause" if you will.  MCC command 10022 with an argument of "1" (set pause).  This works from the Launcher really well as:

Code: [Select]
/Applications/Media\ Center\ 28.app/Contents/MacOS/Launcher.app/Contents/MacOS/Launcher /mcc 10022,1
Now my lock and pause workflow works as it should.  ...and it's not making a TCP connection to the MC media network service any more.  Just using the launcher, which I like a little better.

Thanks again for fixing the Launcher!

Brian.
Logged
Pages: [1]   Go Up