Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

How to pull a password from Keychain to use in a script Apps
Quite some time ago, I needed to create a script which would mount a network volume. I did not want to hardcode username and password into the script, so I kept looking for ways to accomplish this using OS X’s built-in Keychain. The following example uses a script to mount a network volume, using variables for the currently logged-in user, and fetches its password from the Keychain. Of course, you can do other things with this approach, so I figured it might be of use to someone out there.

The following is a combination of these 2 links:
http://hintsforums.macworld.com/showthread.php?t=163359
http://blog.macromates.com/2006/keychain-access-from-shell/

This script gets the password for the currently logged in user and pulls its password from the Keychain. It then mounts a share using the variables without hardcoded username/password. The mount point is not in /Volumes on purpose, because mounting the volume would not work for User B when Fast User Switching is in use and User A remains logged in without having unmounted the volume. echo $USER gets the username of the currently logged in user.
$(get_pw) contains the password retrieved from the user’s keychain.

In this case I am mounting an AFP volume, but it could be any other protocol, as well as something completely different which has nothing to do with mounting volumes.

get_pw () {
  security 2>&1 >/dev/null find-generic-password -ga $USER 
  |ruby -e 'print $1 if STDIN.gets =~ /^password: "(.*)"$/'
}
mkdir ~/Data
mount -t afp afp://$USER:$(get_pw)@10.0.77.3/Data ~/Data
Before running this script you have to create a new entry using Keychain Access with the username and its (server) password.

The steps are as follows:

Manually create a Keychain entry for the AFP user account. To do so open Keychain Access.app and hit cmd+n. Keychain Item Name does not matter, but Account and Password have to be filled out with the user’s username+password. That is the login info of the AFP account on the server!

Then create a shell script the way you prefer. I usually use pico, but there’s also a "run shell script" workflow in Automator if you want to use it. The script is shown above. Here’s a short explanation of what’s happening in the script:

We issue the security command which itself is able to read info from the keychain. It fills the variable $get_pw with the password it retrieved from the keychain. That’s why you need to create the keychain entry mentioned above. Instead of hardcoding which user’s password to get we use another variable called $USER. This always represents the currently logged in user (try echo $USER in Terminal as an example). In the next step we create the mount point, but instead of the default location (/Volumes) we use ~/ to ensure the mount point is inside the user home. This prevents the mount point from being already in use when using Fast User Switching. The last step then mounts the desired share using both variables. In my case that is the share Data on the server 10.0.77.3 which will be mounted at ~/Data.

In order for this to work you need to use network user accounts (Open Directory, LDAP, Active Directory, etc.) OR have to use the exact same username (password does not matter) for the local account and the account on the afp server. That is because $USER will always return the currently logged in user’s name which will be the local account if you are not using network accounts. In my case it was perfect that way, because I use network accounts anyway. You could always replace $USER in the script with jon.doe while losing the flexibility of the solution. I wanted a script without hardcoded usernames or passwords which could get the needed information dynamically from the keychain, which is exactly what this does.
  Post a comment  •  Comments (4)  
  • Currently 3.17 / 5
  You rated: 5 / 5 (6 votes cast)
 
[10,209 views] Email Article To a Friend View Printable Version
Send an RSS item from ReadKit to Safari's Reading List Apps
ReadKit (http://www.readkitapp.com) is an RSS reader that synchronizes with multiple RSS services. It supports sending articles to read-later services such as Instapaper, Readability and Pocket. However, out of the box there is no way to send an article to Safari's Reading List (aside from manually copy-and-pasting the URL into Safari).

Reading List (RL) is very handy if you have multiple iOS devices, since articles in RL are automatically synchronized and downloaded on each devices. Below, I will describe a simple service that import the currently selected article in ReadKit into RL.

  • Open Automator and create a new Service. Call the Service "Add to Reading List"
  • Select Service receives: "no input"
  • Click on the next drop-down box, select "Other..." and find ReadKit in the Applications folder
  • On the left-hand side sidebar, select "Utilities" and then double-click the action "Run AppleScript"
  • Copy and paste the content of this script into the window
  • Save the service and quit Automator.
  • To add a keyboard shortcut, go to System Preferences -> Keyboard -> Keyboard Shortcuts and select "Services"
  • Find the "Add to Reading List" service and add your preferred shortcut.
  Post a comment  •  Comments (1)  
  • Currently 2.57 / 5
  You rated: 2 / 5 (7 votes cast)
 
[6,572 views] Email Article To a Friend View Printable Version
Turn off an iPad or iPhone without touching the power switch iOS devices

My friend Frank works for Canon in Manhattan, and occasionally gives demos in a room with locked-down iPads. Sometimes those iPads need to be rebooted—but Frank has no access to the sleep/wake switch ostensibly required to power off an iPad.

In the past, I’ve suggested that Frank “reset” something (under Settings -> General -> Reset) that’s easy to set again; resetting Location & Privacy settings doesn’t mess too much up, and it restarts the iPad when you tap it.

But there’s a better way. Also in the Settings app, head to General -> Accessibility, and and turn on Assistive Touch. That adds a draggable dot control to your screen, meant for people with physical challenges that prevent them from triggering certain iOS actions the traditional way. Tap the dot, then tap Device, and finally tap and hold Lock Screen—a software equivalent of the sleep/wake button. After a few moments, the familiar Slide to Power Off message appears, and you can shut the iPad down.

The same technique works on the iPhone.

  Post a comment  •  Comments (4)  
  • Currently 3.25 / 5
  You rated: 5 / 5 (8 votes cast)
 
[42,477 views] Email Article To a Friend View Printable Version
Cache Google Maps for offline access on iOS Apps
Google's recent update for the Maps app introduced a variety of new features and improvements. One of those is the ability to save map data for offline access.

If you use Google Maps on a Wi-Fi only iPad, or if you'll be traveling somewhere where cellular data is spotty, knowing how to enable offline caching of map data is pretty important. CNet explained the trick recently.

First, you'll need to zoom in a bit; you can't cache a widely-zoomed-out map view. Then, when you're at the spot you'd like to cache, type OK maps into the search box, and then tap Search.

When you do that, a Google Maps icon will appear briefly, followed by a message indicating that your map data was saved. Now, even when you're offline, if you navigate to your cached areas, the map data will appear.
  Post a comment  •  Comments (6)  
  • Currently 3.57 / 5
  You rated: 2 / 5 (7 votes cast)
 
[15,105 views] Email Article To a Friend View Printable Version
Delete files without emptying the Trash System 10.8

Long ago, we detailed a (rather scary) way to delete files without needing a stop in the trash can. A recent thread on StackExchange brought the issue up again, and some folks there provided other, less scary approaches.

Why would you want to delete a file without needing to choose Empty Trash? Here’s one example: You have some files in the Trash on your Mac that you’re not ready to pull the trigger on forever. Now you connect a USB drive and have files on it that you wish to dispose of. If you drag those files to the Trash, you have to select Empty Trash to do it—which means deleting the files from both the drive and your Mac itself.

Most Hints readers know about the rm Terminal command, which lets you remove files instantly and without a trip to the Trash. But that’s always the most convenient approach. One tip at StackExchange suggests wrapping that Terminal command in an Automator action, which you could then store in the Dock or add as an OS X Service for easy access from the Services menu. You can see the Automator action at StackExchange.

There are also third-party apps like Trash X and Trash Without that help you accomplish the same goal.

  Post a comment  •  Comments (9)  
  • Currently 2.33 / 5
  You rated: 2 / 5 (9 votes cast)
 
[26,661 views] Email Article To a Friend View Printable Version
Developers: Prevent GateKeeper 'Damaged application' warning on Java apps System 10.8
If you create an application bundle to start a Java application as a regular Mac app, you will get a message that the application is damaged when you try to run it on Mac OS Mountain Lion with GateKeeper active.

The error is caused by the fact that the Java stub application is signed by Apple, and Apple's signature will not be valid for your application.The codesign tool will give the following message:

codesign -d MyJavaApplication.app
MyJavaApplication.app: invalid signature (code or signature have been modified)

The best solution is to sign your application with your Apple Developer key, but if you do not have one you can still sign your application with an ad-hoc key, and replace the Apple signature that will cause this message. To do so run codesign with the following options:

codesign -s - --force MyJavaApplication.app

The user will still have to allow running the application the first time by using the right-click (Control-click) -> Open approach, but at least the user won't see the (incorrect) message that the application is damaged.

Lex adds: I haven't tested this one.
  Post a comment  •  Comments (1)  
  • Currently 2.71 / 5
  You rated: 4 / 5 (7 votes cast)
 
[6,453 views] Email Article To a Friend View Printable Version
Generate a list of Reading List URLs Web Browsers
Perhaps you use Safari's Reading List feature to save various Web articles for later reading. But maybe your Reading List is so overwhelming that you'd prefer to export a simple list of URLs to keep track of—or to open in an app besides Safari.

Over at StackExchange, Rob Mathers offers up a quick Python script to do just that. Copy Mathers's Python script into a plain text document, and name it something like readinglist.py. Next, make it executable; you can use the Terminal command chmod +x readinglist.py.

Run the script—which loops through the proper section of the ~/Library/Safari/Bookmarks.plist file where those URLs are stored—and it will generate a list of the URLs in question. If you'd like to save the URLs to a file, use a command like ./readinglist.py > urls.txt to do so.
  Post a comment  •  Comments (1)  
  • Currently 2.10 / 5
  You rated: 2 / 5 (10 votes cast)
 
[7,904 views] Email Article To a Friend View Printable Version
Navigate directly to recently accessed files and apps Apps
Sometimes, an old hint is so good, it bears repeating. Years ago, we shared a hint involving the Recent Items section of the Apple menu.

Next time you're looking at that particular section, hold down the Command key. The names of your recent apps and files—which you could otherwise select to launch as desired—will change. For example, if your Recent Apps list included Acorn, that item would change to Show Acorn in Finder. And yes, this works with documents, too.

So if you very quickly want to find specific files in the Finder that you know you used recently, the Apple menu's Recent Items section, in tandem with the Command key, can help you out in a jiffy.
  Post a comment  •  Comments (9)  
  • Currently 2.56 / 5
  You rated: 2 / 5 (9 votes cast)
 
[5,619 views] Email Article To a Friend View Printable Version
How to use Command-Tab to escape screen sharing System 10.8
Since OS X 10.6, when you're screen sharing and looking at a remote Mac's screen, you cannot successfully use Command-Tab to switch out of a screen sharing window, because the command is sent to the remote machine instead.

I recently found a way around this by using Quicksilver. With Quicksilver installed, the key combination is not sent to the remote machine, but rather to your local Mac instead—once you've summoned Quicksilver. When the Quicksilver window shows up, focus goes to local machine, and Command-Tab is also sent to the local machine.

Lex adds: And that's just the tip of the iceberg. In his testing, my colleague Dan Moren found the same behavior works with Alfred; he could trigger Alfred's shortcut while screen sharing, and the app would launch on his local Mac, and thus Command-Tab would begin working on the local Mac instead.

I'm a LaunchBar guy, though, and when I tried to trigger LaunchBar on my Mac—which I've set to use the Command-Space shortcut that defaults to Spotlight—it triggered Spotlight on the remote computer instead. But that gave me an idea: I instead switched to using my Spotlight keyboard shortcut (which I've set to Control-Space). That in turn launched Spotlight on my local Mac, at which point I too could use Command-Tab to switch away from my screen sharing window via the keyboard.
  Post a comment  •  Comments (6)  
  • Currently 1.58 / 5
  You rated: 2 / 5 (12 votes cast)
 
[7,819 views] Email Article To a Friend View Printable Version
Click the Apple and Notification Center menu items more easily System 10.8
This hint is an oldie but a goodie, and we could only find it mentioned in comments on older hints. If you don't know it, you'll want to; if you already knew it, pay it forward to Mac users who are spending too much time fussing with the mouse.

The Apple menu sits at the top left of your menu bar, and the Notification Center icon sits at the top right. For years, though, OS X has made clicking menu items in either position simpler than it might appear. You needn't move the mouse cursor to precisely the slim confines of either icon when you want to click on them. If you slam your mouse all the way to the top left corner of the screen, well beyond the perimeter of the Apple icon, and click—you'll still successfully trigger the Apple menu.

The same trick works with the Notification Center menu at the upper right: Move the mouse all the way to that corner, fretting not about whether your cursor is actually atop the icon, and your click will still register as desired.

Thus, in keeping with the tenets of Fitts's Law, you essentially have an infinite amount of clicking space to access either menu.
  Post a comment  •  Comments (4)  
  • Currently 3.88 / 5
  You rated: 4 / 5 (8 votes cast)
 
[5,589 views] Email Article To a Friend View Printable Version