Delete ‘Where From’ metadata from files – Mac OS X Hints.
I knew I would have to do this often, so instead of running a shell script every time I wanted to strip the Where From, I wrote an AppleScript
This is why and how you write scripts. đ
Delete ‘Where From’ metadata from files – Mac OS X Hints.
I knew I would have to do this often, so instead of running a shell script every time I wanted to strip the Where From, I wrote an AppleScript
This is why and how you write scripts. đ
This article includes ten more little known Automator hacks, not included in the guide, that you can create in a few easy steps.
on makeuseof.com. (Thanks to @marrathon.)
If you have a bash
script with a while
loop that reads from stdin
and uses ssh
inside that loop, the ssh
command will drain all remaining data from stdin
((This is not only true for ssh
but for any command in the loop that reads from stdin
by default)). This means that only the first line of data will be processed.
I encountered this issue yesterday ((I won’t go into details here, since it is for a very specialized purpose. I will say that it involved jot
, ssh
, an aging Solaris based network appliance, and some new fangly XML/Web 2.0)). This website explains why the behavior occurs and how to avoid it.
A flawed method to run commands on multiple systems entails a shell while loop over hostnames, and a Secure Shell SSH connection to each system. However, the default standard input handling of ssh drains the remaining hosts from the while loop
Update: In one of those embarrassing “You know there is a checkbox for that!?” moments, @rogueamoeba points out there is in fact a checkbox for this under Preferences “Automatically Transmit To:”
Airfoil from Rogue Amoeba is a wonderful application that allows you to stream audio from your computer to any device that will receive Airplay audio or run the Airfoil Speaker application. This includes all iOS devices. I use it stream audio to any room I may be in where I just hook an iPod touch or the iPhone up to the stereo.
The one drawback is the UI, which only allows to the devices to stream to on the Mac that is streaming. So I’ll be in the kitchen, where a 1G iPod touch is permanently hooked up to some speakers, turn on the iPod touch, start the Airfoil speakers app, then walk to the Mac in the living room, select the iPod touch in the Kitchen and walk back to enjoy the music. Wouldn’t it be great if Airfoil automatically picked up the iPod when it appears in the list?
Luckily Airfoil has AppleScript support. It is actually very easy. I have named all my iOS device to start with either “iPhone”, “iPad” or “iPod touch” so I can make Airfoil connect to all devices that are running the Airfoil app with
tell application "Airfoil" connect to every speaker whose name starts with "iP" end
Now we need to keep running this command periodically in the background. I could setup a launchd plist for that, but AppleScript provides a simpler solution. Scripts that are saved as “Stay Open Applications” have an idle
handler that is called after a certain number of seconds. See the details at the AppleScript Language Guide here.
So we wrap the command in an idle
handler and add some checking to see if Airfoil is running so we don’t force launch Airfoil:
property idleTime : 30 -- in seconds on run idle -- call idle on launch end run on idle tell application "System Events" if exists application process "Airfoil" then -- check if Airfoil is running tell application "Airfoil" connect to (every speaker whose name starts with "iP" and connected is false) end tell else -- if Airfoil is not running script can quit, too tell me to quit end if end tell return idleTime end idle
The value returned from the idle
handler is the time (in seconds) until it gets called again. This will leave other speakers (that don’t start with “iP”) such as the local speakers and any Airport Express speakers unaffected.
Save this as an application and make sure to select the “Stay Open” option. Then find the application and double click to launch. Start and quit Airfoil speakers app on your iOS devices and listen to Airfoil connect automatically.
A little command line knowledge goes a long way
via Strata Gems: The timeless utility of sed and awk – O’Reilly Radar.
ssh
TricksI found this website with a bunch of ssh
tricks. Some highlights:
Compare a Remote File with a Local File
ssh user@host cat /path/to/remotefile | diff /path/to/localfile -Useful for checking if there are differences between local and remote files.
opendiff
((Part of the Developer Tools installed with Xcode)) and bbdiff
((One of the tools installed by BBEdit)) do not use stdin
for their input, but you can work around that by copying the file to /tmp
first:
scp user@host:/path/to/remotefile /tmp/remotefile && opendiff /path/to/localfile /tmp/remotefile
SSH Connection through host in the middle
ssh -t reachable_host ssh unreachable_hostUnreachable_host is unavailable from local network, but itâs available from reachable_hostâs network. This command creates a connection to unreachable_host through âhiddenâ connection to reachable_host.
Using the -t
option uses less overhead on the intermediate host. Same trick is used later in the article where you directly attach to a remote screen
session:
ssh -t remote_host screen -r
Though I prefer using screen -DR
. Read the man page for details.
The next one however didn’t do anything for me, I suspect there is a piece missing in the command somewhere:
Remove a line in a text File
sed -i 8d ~/.ssh/known_hosts
However there is a dedicated tool for this: use
ssh-keygen -R host
instead. I re-image some machines over and over again and then run into the ssh host key errors. This is very useful.
John C Welch has posted two scripts that convert Numbers files.
It’s Thanksgiving here in the US. To keep you happy with minimal effort on my side I’ll give you a whole bunch of services to explore, without me (or you) having to write any of them.
Open System Preferences, select the Keyboard preference pane, select the Keyboard Shortcuts Pane and then from the list on the left select “Services.”
There you will find a long list of pre-installed services many of which are disabled by default. Go through the list and enable those that sound promising. “Get Result of AppleScript” and “Add to iTunes as Spoken Track” are two of my favorites.
Any services you have built yourself will also appear in this list. You can disable or re-enable them to keep your context menu trim.
This pane is also where you assign or change keyboard shortcuts. So if there is a service that you use frequently you can further optimize your workflow with a keystroke.
So there you are doing your work and of course being the geeks that we all are you have about three hundred windows open, give or take a few hundred. Then the iChat icon starts bouncingâŠ
Now you might be very organized and have the iChat window in a certain spot on the screen or even on a certain space in Spaces. You might be a whiz with ExposĂ© and immediately find the right iChat window in the myriad of windows that are open. Or you might have one or two 27″ displays and not really care about this.
But for the rest us, wouldn’t it be nice if say a small window floated into the screen with a notification and the person who sent the message and maybe even the message? And it would have to be unobtrusive and float away just as quickly. You could glance at the notification and decide there and then wether it is necessary to dig out that iChat window.
Incidentally, this is what Growl really does well.
This window will float serenely in front of everything for a few seconds.
And with the scripting interface in iChat it is fairly simple to set up. After installing Growl, take this script:
property growlAppName : "Growl iChat" property notificationNames : {"Buddy Became Available", ÂŹ "Buddy Became Unavailable", ÂŹ "Message Received", ÂŹ "Completed File Transfer"} property defaultNotificationNames : {"Buddy Became Available", ÂŹ "Buddy Became Unavailable", ÂŹ "Message Received", ÂŹ "Completed File Transfer"} using terms from application "iChat" on buddy became available theBuddy my registerWithGrowl() tell application "iChat" tell theBuddy set theTitle to full name & " became available" set theDesc to status message set theIcon to image end tell end tell my notify(theTitle, theDesc, theIcon, "Buddy Became Available") end buddy became available on buddy became unavailable theBuddy my registerWithGrowl() tell application "iChat" tell theBuddy set theTitle to full name & " went away" set theDesc to status message set theIcon to image end tell end tell my notify(theTitle, theDesc, theIcon, "Buddy Became Unavailable") end buddy became unavailable on message received theText from theBuddy for theTextChat my registerWithGrowl() tell application "iChat" set theIcon to image of theBuddy set theTitle to full name of theBuddy end tell my notify(theTitle, theText, theIcon, "Message Received") end message received on completed file transfer theTransfer my registerWithGrowl() tell application "iChat" tell theTransfer if transfer status is finished then if direction is incoming then set theTitle to "Received File " set theDesc to "from " else set theTitle to "Sent File " set theDesc to "to " end if set theTitle to theTitle & (file as string) set theDesc to theDesc & full name of buddy end if end tell end tell my notify(theTitle, theDesc, theIcon, "Message Received") end completed file transfer end using terms from on registerWithGrowl() tell application "GrowlHelperApp" register as application growlAppName all notifications notificationNames default notifications notificationNames icon of application "iChat" end tell end registerWithGrowl on notify(theTitle, desc, icondata, notificationName) tell application "GrowlHelperApp" if icondata is "" or icondata is missing value then notify with name notificationName title theTitle description desc application name growlAppName icon of application "iChat" else notify with name notificationName title theTitle description desc application name growlAppName image icondata end if end tell end notify
Copy the code into AppleScript Editor and save the file as “Growl iChat” (as a script file) in ~/Library/Scripts/iChat/
In iChat, go to Preferences -> Alerts and select the Event “Message Received”, check “Run Applescript” and choose “Growl iChat.scpt”
I also setup the script to react to “Buddy Becomes Available,” “Buddy Becomes Unavailable” and “File Transfer Completed.” The great thing is that you don’t have to enable all notifications. You can even set it up individually so that you get notifications for some buddies, but not others. It should be easy to adapt the script to more actions if you wanted to.
Note: update for macOS Ventura
So youâre writing this email explaining to a customer or colleague on how to do some really cool thing (say hide a file in the Finder) in Terminal. The command for that is chflags
, but of course you canât remember the exact syntax. So you open Terminal and write man chflags
and find the correct options.1
However reading longer man pages (try ssh
or bash
) in the Terminal can be kind of painful. Iâm sure some of you have encountered this command before:
man -t chflags | open -f -a "Preview"
which uses the -t
flag to pass the output to groff
and generate a postscript file which we then pipe into the Preview app, using open
âs -f
option to pipe the stdin into a file to open
in a GUI app. Preview will then convert the postscript to PDF and display the result.
I think this started to work in Tiger and you should immediately go and add this command to your shell’s profile
.2 Which is nice but you still have to make the roundtrip to the Terminal.3
Enter Snow Leopard Automator Services. Open Automator. Create a new service. Leave the settings to work on âtextâ in âany applicationâ. Search for the âRun Shell Scriptâ action and double click to add to the workflow. Leave the Shell at â/bin/bashâ but set the âPass Inputâ option to âas arguments.â
Replace the default code with
man -t "$1" | open -f -a /Applications/Preview.app
Save the Service and give it a nice name, such as âOpen Man Page.â
Then in any application4 you can ctrl/right/double-finger click on a word and âOpen Man Pageâ will be an option in the menu.5 You can even go to System Preferences -> Keyboard -> and add a keyboard shortcut to the command.6 If any other command in the man page strikes your curiosity, just ctrl/right/double-finger click the word in Preview and select âOpen Man Pageâ again.
Another rarely known but quite useful trick is that you can create hyperlinks to man pages with the x-man-page://command
URL.7 This will open the man page in man
in a new Terminal window. This is especially useful in IM sessions.
chflags [no]hidden /path/to/file
↩function preman() { man -t "$@" | open -f -a "Preview" ;}
↩