Jump to content
Flirc Forums
Chris!

Using Flirc to put a Mac to sleep

Recommended Posts

Hi all,

Akira has asked a question that has me stumped and wonder if anyone can help out.

We're trying to put a mac to sleep. I guess there are two solutions but I can't figure them out:

1) use the short cut: shift+ctrl+eject key

2) Invoke a script that sleeps the mac

Can anyone help?

pleasant regards,

Chris!

Share this post


Link to post
Share on other sites

I tried the script 'solution', but can only implement it as a service, which means it is unavailable when XBMC is running.

In addition I am looking for a way that allows me to start XBMC using a button on the remote. Any suggestions would be more than welcome (putting a MAC to sleep is actually why I bought Flirc, thinking it could do this "out of the box". I am still stumped why Flirc does not offer MAC users a Mac keyboard. After all, isn't that what Flirc is all about?

Share this post


Link to post
Share on other sites

I think I may have cracked it. Just to be clear, I am using a 2012 Mac Mini with Lion preinstalled as an XBMC media streamer linked to an AV receiver (and projector) with a Harmony 900 RF-IR remote control and Flirc in one of the Mini's USB ports. I bought Flirc because I had problems with both the standard Harmony Plex setup and later RemoteBuddy in that the first was unable to wake the Mini. Remote Buddy could do it but not as consistently as I would like. Flirc will wake up the Mini, even if I sometimes have to repeat the key press (I tend to use the enter key).

This is what I did.

I set up the Harmony using one of the two recommended remotes (Panasonic TC-P65VT30 or Samsung LN46C650L1F) and made sure all keys were occupied (doesn't mater with what but make a note of it for later use). I also defined a soft key for "Sleep" and assigned a random command to it

I used AppleScript Editor to create two scripts: the first will put the Mini to sleep:

do shell script "pmset sleepnow"

the second starts XBMC:

application "XBMC" activate

In order to link these scripts to shortcut keys I had to use an external app and I chose FastScripts (free with a max of 10 shortcuts) to which I linked these two scripts (Ctrl+Sm Ctrl+X). Using the Flirc.app I associated Ctrl+s and Ctrl+x with the relevant buttons on the Harmony. In the Harmony activity I had also set things up in such a way that every time I switch away from using the Mini the "Sleep" button is activated.

That did it. I can now call up XBMC from the Mini desktop and when I switch away from using the Mini it will be put in sleep mode (fortunately, the Harmony will also use this script when switching everything off in my home theatre).

All this would have been superfluous I think if the flirc.app had had a Mac keyboard with the eject key so I could have used Opt+Cmd+Eject for sleep and I would not have had to mess around with scripts and external apps. On the positive side, I have learned a little bit about using AppleScripts (I am a novice Apple user).

PS. The scripts MUST be moved to ~\Users\username\library\scripts

Share this post


Link to post
Share on other sites

Woah, cool. Agreed that the apple button would be easier.

If Jason knows their maybe a command line key modifier.

Pleasant regards,

Chris!

Share this post


Link to post
Share on other sites

Actually, you can make AppleScripts and/or shell scripts into Automator services really easily, and they can be called by any keyboard shortcut you want to assign in system preferences, without the need for any third party software at all. You could potentially get a ton of mileage out of your flirc on a Mac this way, making shortcuts for almost anything your computer can do, and they can be set up to work only when pressed from individual applications, or from any application universally.

  1. Open Automator and create a new service (there's a Service template you can select from the menu when you first launch Automator)
  2. In the far left column, choose Utilities
  3. For this example, I'll choose Run Shell Script from the second column. Double-click it.
  4. In the main workflow area, edit the text of the shell script to say simply:
    pmset sleepnow


  5. Notice the top part of the workflow area lets you choose context. From the left pulldown, choose 'no input.' By default a new service will work text from any application, but if you want your sleep command only to work when XBMC or something else is in focus, just browse to the app from the pull down menu near the top right.
    post-767-0-32999000-1342426059_thumb.png
  6. Save your service. I'll call this example service 'sleep'. Your new service will be saved in ~/Library/Services/ (the tilde (~) represents your home folder).
  7. If you specified 'any application' in step 5, you should now be able to get to your new service from the menu bar of any app. For example, if Finder is in the foreground, click the Finder menu -> Services, and you should see your service. If you chose to make your service work from only a specific app, bring that app into focus first and then check the menu.
    post-767-0-06374500-1342426100_thumb.png
  8. Now, to assign a shortcut key: open System Preferences -> Keyboard and choose the Keyboard Shortcuts tab.
  9. In the left column, choose Services. On the right, under General, you should see the 'sleep' service we created.
  10. Highlight the service and click the 'add shortcut' button (or double-click it).
  11. Press the keyboard shortcut combination you want to assign.
    post-767-0-48896800-1342426159_thumb.png

That's it, you're done!

Edit: It may be worth noting that on Lion this was broken at first for me. When I just redid this to make sure my instructions were accurate, I could see my example sleep service in the Services submenu under any application, and clicking on it put the machine to sleep, but the shortcut key I assigned wasn't working. I fixed this by changing the automator workflow, saving, changing it back and resaving. Simply rebooting may have done the trick too.

Edit 2: I just noticed that there's already a service called Put System to Sleep in System Preferences -> Keyboard -> Keyboard Shortcuts. Highlight Services, and it will be under the Text section. So technically if all you want is a quick sleep shortcut, you could start this process at step 8, but expand the Text section instead of the General section in step 9. I'll leave the rest of the tutorial though, as it demonstrates how you could run other scripts that aren't already provided in the menu system.

Share this post


Link to post
Share on other sites

I'm actually having a lot of fun with this and flirc. Perhaps I'll turn this into a more complete and generic tutorial in the how-to section.

Share this post


Link to post
Share on other sites

Digitalboy0 this discussion was started in a media keys thread and transferred here by Chris. In the earlier discussion I did explain that I used the Automator first, but I found that the shortcut key would not work in all applications even though it was listed as a service!

Share this post


Link to post
Share on other sites

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