Remove this ad
avatar

ericn

superstar

Posts: 284

Lead

Apr 22 10 10:58 AM

Tags : :

Originally Posted by EricN on March 28, 2010 at 10:30am


The Apple's Services Menu has been completely overhauled in Snow Leopard. It is now easy to both use and set up your own services. Moreover, Apple has also made it simple to attach keyboard shortcuts to Service Menu Items. This is so useful that I've decided to make a quick tutorial: everyone should know how this works.


In case you are not familiar with it, the Services Menu provides quick access to system wide services when using any application. It is found in the main application menu of any application.





As an example, I'll run through how to set up a service that rotates your display. First, download fb-rotate from this post. Then put it in a convenient folder (I've put it in ~/Library/Application Support/RotateDisplay/). Now, Launch Automator (found in your Applications folder). You will be confronted with a choice of templates. Choose the Service template.


At The top of the Automator window, there will be two drop down menus:





For our purposes, we'll choose, as shown: Service receives "no input" in "any application". (When setting up other sorts of services, the other options maybe useful.)


Now select, from the first column, "Utilities" and, from the second column, grab "Run Shell Script" and drag it into the workflow pane.





Our first service will rotate your display to the 180º orientation. Begin by deleting the word "cat" from the script window. Then find fb-rotate in Finder and drag the file into the script window.





This will insert the path to fb-rotate in The script window. It should look something like:




Now put single quotes around the path and add the following text at the end: -d 0-r 180


If you are using a Macbook, you are good. If you are using a Modbook, you need to add another line:

/usr/bin/osascript -e 'tell application "TabletDriver" to set orientation of tablet 1 to landscape flipped'


Automator's script window should look something like:





Clicking on the Run button will test the script. If it works, save it using the name that you want to appear in the Services Menu.





The scripts for rotating the display into the other orientations would be analogous:

Rotate Display 0º:

'/Users/<your user name>/Library/Application Support/RotateDisplay/fb-rotate' -d 0 -r 0

/usr/bin/osascript -e 'tell application "TabletDriver.app" to set orientation of tablet 1 to landscape'


Rotate Display 90º:

'/Users/<your user name>/Library/Application Support/RotateDisplay/fb-rotate' -d 0 -r 90

/usr/bin/osascript -e 'tell application "TabletDriver.app" to set orientation of tablet 1 to portrait'


Rotate Display 270º:

'/Users/<your user name>/Library/Application Support/RotateDisplay/fb-rotate' -d 0 -r 270

/usr/bin/osascript -e 'tell application "TabletDriver.app" to set orientation of tablet 1 to portrait flipped'


[Warning: if you are using a Macbook or Modbook with the Intel GMA graphics do not use the scripts for 90º or 270º. You may not be able to rotate back out.]


A Modbook owner is likely to use this service a lot, so might be nice to have a keyboard shortcut that will run the service. To this end, launch System Preferences, select the keyboard pane and find your newly minted service in the Keyboard Shortcuts tab.




Clicking to the right of the services name opens a small text box into which you can enter your shortcut. Be sure that you’re not assigning a shortcut that is already in use.


Now that you've created these display rotation services, you are ready to add more. Use the "Run AppleScript" Automator action to make a service of any AppleScript, such as any of these (or these or these). Follow the directions at Geek and Mild to make a cool title case service or get acquainted with Automator and make a service of any Automator action. Have Fun.

Quote    Reply   
Remove this ad
Remove this ad
avatar

ericn

superstar

Posts: 284

#1 [url]

Jul 16 10 12:42 AM

A recent post at MacScripter describing a simple installer for services has inspired me to create an installer for the rotation services described above. 

My installer, RotationServices.app, installs the Unix utility fb-rotate in the user's Application Support folder, as well as installing the rotation services. If you run it on a computer that supports portrait orientation, it will install all four rotation services. Otherwise, it just installs the 0º and 180º services. 

If you want keyboard shortcuts for the installed services, you will need to create those manually as described in the post above.

Download: RotationServices.zip  [Installer in the zip-file].

As of Jul 16, 2010, the installer should install rotation services properly in both MacBooks and Modbooks. I don't know about iMacs.

Quote    Reply   
avatar

ericn

superstar

Posts: 284

#5 [url]

Aug 5 10 3:06 PM

This morning, Mac OS X Hints published a cool Services hint that allows you to temporarily sweep all clutter off your Desktop. The Service hides all the icons on your Desktop, while still allowing you access to those items in the Finder. Run the Service again, and your clutter returns.


As happens sometimes, the original hint didn't quite work, but was corrected down in the comments. The properly working Service is based on the following AppleScript:


try

set myAnswer to ((do shell script "defaults read com.apple.finder CreateDesktop") as integer) as boolean

on error

do shell script "defaults write com.apple.finder CreateDesktop 1"

set myAnswer to true

end try

do shell script "defaults write com.apple.finder CreateDesktop " & (((not myAnswer) as integer) as string)

tell application "Finder" to quit

delay 1

tell application "Finder" to launch


To make things easier, I've put this in my handy-dandy Service installer.


Download: HideShowDesktopService.zip


EricN


Quote    Reply   
Remove this ad
avatar

ericn

superstar

Posts: 284

#6 [url]

Sep 23 10 11:32 PM

I though I'd add another convenient Service to the pile. 

Recently, I've been using the following AppleScript to show and hide invisible files (Unix files and folders, .config files, etc.): 

try

set ShowAllFiles to do shell script "defaults read com.apple.finder AppleShowAllFiles -bool" as boolean

on error

set ShowAllFiles to false

end try


if ShowAllFiles is true then

do shell script "defaults delete com.apple.finder AppleShowAllFiles;killall Finder"

else

do shell script "defaults write com.apple.finder AppleShowAllFiles -bool YES;killall Finder"

end if


So I made a Service out of it and plugged it into my Service installer.


Download: ToggleInvisiblesService.zip


EricN



Quote    Reply   
avatar

ericn

superstar

Posts: 284

#8 [url]

Sep 24 10 2:54 PM

In older, non-NVIDIA, Modbooks, it won't work properly for the 90º and 270º orientations. Rather produces stuff like this:


However, it works fine for the 180ª orientation, and, in the event that you get stuck in a distorted orientations, "fb-rotate -d 0 -r 0" still gets you back to the normal display orientation.

And you can still use RotationServices.app (above) to install Rotation Services on your non-NVIDIA Modbook or MacBook — it will just install the 0º and 180º Services. 

EricN

Quote    Reply   
avatar

ericn

superstar

Posts: 284

#9 [url]

Sep 26 10 10:44 PM

Yet another Service:

When cleaning up the assorted messes that I make on my computer, I often gather similar files and put them in a new folder. So I've created a Finder Service based on the following AppleScript to help with that: 


set homeFolder to (path to home folder) as string

set libraryFolder to (path to library folder from user domain) as string

try

tell application "Finder"

set theSelection to selection

set selectionFolder to folder of item 1 of theSelection

if ((folder of selectionFolder as alias as string) does not contain homeFolder) ¬

or ((selectionFolder as alias as string) contains libraryFolder) then

set selectionFolderP to POSIX path of (selectionFolder as alias)

display alert "Moving Files from the " & name of selectionFolder & " Folder" & return & "May Be Unwise." message "You have selected " & (count of theSelection) & " file(s) to move out of the folder:" & return & selectionFolderP & return & return & "Be sure that is what you want to do." buttons {"Cancel", "Move Files"} as warning

if button returned of result is "Cancel" then return

end if


set newFolder to make new folder in folder of item 1 of theSelection

move theSelection to newFolder

reveal newFolder

activate

set current view of window 1 to column view

delay 0.5

tell application "System Events" to key code 36

end tell

end try


This script and the resulting Service (New Folder from Finder Selection) take a selection of files or folders in the Finder and put them in a newly created folder which can then be renamed. It is pretty nifty.


Of course, I've made an installer for the Service below.


Download:  FolderFromSelection.zip


Quote    Reply   
Add Reply

Quick Reply

bbcode help