Fun with SED!

(Found this sitting in my blog’s drafts folder.. only 11 years old but all of it still just as valid today!)

A couple of shell scripts for renaming files on the command line.

# Replaces JPG in any file with jpg 
for ii in * ; do ARG1=`echo $ii | sed 's/JPG/jpg/g'` ; mv $ii $ARG1 ; done

Stany’s renaming scripts:

#!/bin/bash
# Mass REname of english filenames
# relies on fixfilename regexp engine

PATH=$PATH:/Users/stany/bin
echo
for ii in * ; do ARG1=`echo $ii | fixfilename `   ; echo -n "." ; mv "$ii"  "$ARG1" ; done
echo
#!/bin/bash
# the fixfilename regexp engine

PATH=$PATH:/raid0/tools
sed 's@(@@g;s@)@@g;s/ /_/g;s/\,//g;s/\&/and/g;s/_-_/-/g;s/-_/-/g;s/\!//g;s/\;//g;s/\]//g;s/\[//g;s/%20/_/g' 

A combined version…

#!/bin/bash
for ii in * ; do ARG1=`echo $ii | sed 's@(@@g' | sed 's@)@@g' | sed 's/ /_/g' | sed 's/\,//g' | sed 's/\&/and/g' | sed 's/_-_/-/g' | sed 's/-_/-/g' | sed 's/\!//g' |  sed s/\;//g | sed 's/\]//g' |  sed 's/\[//g' | sed 's/%20/_/g'  `  ; echo -n "." ; mv "$ii"  "$ARG1" ; done
echo

This script will remove the first 4 characters of a filename:

for ii in * ; do FOO=`echo $ii | sed 's/^....//g'`; echo mv \"$ii\" \"$FOO\" ; done

This will echo what it actually does, and place quotes in front and after each filename. In the for ii in * bit you can adjust the regex to match the files you need. So for ii in *.txt will match all the files ending in .txt

Remove the echo to run it, or pipe into shell: | sh

Intro to iOS: Thursday Dec. 6

Tom and I are doing another Intro class this Thursday, Dec. 6th, at 6:30 to 8:30 p.m. at the Main Library Branch.

The class is free but registration is required.

Join us for an introduction iOS, the operating system that runs iPhones and iPads, with Dave and Tom, founders of the Bytown Mac User Group. ByMUG has been helping Ottawans using Mac and iOS devices since 2006. Bring your device and follow along. No device? No problem! This informative workshop will cover the basics and much more! 

If you are attending and have questions.. please send them in in advance so we can be prepared.

Capture all tabs in Safari as URLs to the clipboard

Sometimes you’re doing research and have a pile of tabs (and windows) open and need to get them into a document to share with coworkers… so I went digging and tweaking and found an Applescript that does the job:

tell application “Safari”
set docText to “”
set windowCount to count (every window where visible is true)
repeat with x from 1 to windowCount
set tabCount to number of tabs in window x
repeat with y from 1 to tabCount
set tabName to name of tab y of window x
set tabURL to URL of tab y of window x as string
set docText to docText & tabName & ” – ” & tabURL & linefeed as string
end repeat
set the clipboard to the docText
end repeat
end tell

You can save it as a standalone script and run it from there, or stick into a script item in Automator and run it as a service.. or even call it from the command line as an Osascript.

Looking up Mac specs..

Did I mention I love TextExpander? Yeah.. so, to make a long story short: clients ask me questions about their computers, upgrades, lifespans, etc. I don’t normally remember all the details of their Macs so I get them to send me the Serial Number (Open the Apple menu, click About This Mac and it should be right there.)

Once you have it you can go by Apple’s support site and look it up… but that takes too long.

Make a new TextExpander snippet with Applescript as the content type:
property theURL : ""
set theURL to "http://support.apple.com/specs/#" & (the clipboard)
do shell script "open " & theURL

Then you just copy the serial number, and anywhere you can type use !specs to invoke it and up pops open Apple spec page a few seconds later.

Opening a pile of urls all at once — updated version!

A year or so ago I wrote a post on how to use xargs to open a bunch of urls that were in your clipboard. But it turns out that in newer versions of OS X something broke, deliberately or otherwise, and that method no longer works. Well, it works fine, it’s just *too* fast. So today I needed to check about a hundred urls.. and so it was time to fix that script. I’ve been slowly working on learning Python, so I decided to use that.. and this is what I ended up with:

#! /usr/bin/python
import webbrowser
import pyperclip
import time
url_list = pyperclip.paste()
clean_list = url_list.splitlines(False)
for x in clean_list:

    webbrowser.open(x)
    time.sleep(.5)

It only took me about an hour 😉

What does it do? It grabs the clipboard, splits each line inside the clipboard at the return character, and then there is a loop which tells the browser to open the url .. wait a half second and then do it again.

I’d like to figure out how to grab the clipboard and clean it in one line.. but that’s for another day!

Back to work..

All about games..

There are a few places to get Mac games, other than the App Store.

A few of the larger ones:

Steam lists 2500 games for Mac.
GOG or Good Old Games has 1297 games for Mac.
macgamestore.com, has hundreds in each category.

There are quite a few others, and reviews of them are available online if you want to know which is better or worse than another, and why.

gamersgate.com
gamesrocket.com
amazon.com/mac-game-downloads
gameagent.com
aspyr.com
ubisoft.com
ea.com

The reason we’re here is for games.. and knowing what’s good *before spending money* is important, go read reviews. There are many review sites, and they all have “best of” lists.

http://www.macgamerhq.com/top-games-for-mac/

What do I play?
More like what do I still play? aka what still works on El Capitan.

Osmos
Enigmo

Quinn, a Tetris game, which you can still download from macintoshgarden.org

The Tiny Bang Story, a kids puzzle game.

Cave Story “Doukutsu Monogatari” is a great side scroller ported to the Mac. A bit of fiddling required to get it to work, but worth it! Start here: http://www.cavestory.org/download/cave-story.php

Bungie. What else do I need to say? Yep. Halo. Myth, and many more. Halo 5 just came out.. for Xbox. Although Microsoft did port 2 games to iOS (instead of Windows Phone, what a surprise!) : Halo Spartan Assault and Halo Spartan Strike.

Yes, You can still play Halo, from 2004, using http://halomd.net
You can stil play Myth as well, using Project Magma.

But we’re not limited to just Mac games.. we can run emulators as well. One that I have used on occasion is Boxer, which lets you run DOS games.

Shout out to Ambrosia Software and one of my all time favorites: Avara! Apparently I can run it under emulation. Still making games after 20 years!

I’m sure i’ve missed many, what are your favorites?

Open a pile of links in browser tabs, all at once!

One of things I occasionally do at work is to grab every url for a client’s domains/sites and open them up to eyeball them and see if anything obvious needs fixing.

First I go and copy a list of all the active domains, and clean it up with a “search and replace” script. I end up with a list of url’s, one per line.

After that I copy it all and go over to the Terminal and run a nice little script which I call “tab”. My current default browser then starts sprouting tabs galore.

Here’s the script:


#!/bin/bash
pbpaste | tr "\r" "\n" | xargs -n 1 open

How does it work?

pbpaste provides the contents of the clipboard to the command line (see pbcopy to put things into the clipboard). tr translates characters, in this case from one kind of line end (or return character) to another. An issue with pbcopy from what I can tell! Then the cleaned up clipboard gets pushed to xargs which take the command -n 1 open and builds one open per line of data being fed to it. Yes, xargs is very cool. The open command will then “open the URL in the default browser”.

I am sure this can all be done in Applescript or Automator.. but typing tab and return on the command line is the fastest and simplest for me!

If you want to use the script and are not sure how to take the shell code above and turn it into an actual script.. let me know and i’ll provide instructions (gee, another blog post!).

Desktop Pictures & Automator!

Some people call them wallpapers, I prefer desktop pictures… and I have a big collection of them. hmm. 336 of them in the current rotation, as of this article. I’ve been collecting them for at least a decade, according to the earliest modified date.

b45cc436ed2f93304aa23a7d59

So what do I do with them, and where do I find them? Well, currently I have them all in a folder in my Pictures folder, aptly named Wallpapers. Yeah, I wanted a short name! They come from various sources, but the main one is http://www.desktoppr.co/ What’s so good about that site? Well, it’s linked directly into my Dropbox folder, so syncing an image is as simple as clicking the little cloud icon under the image. Very nice feature. They all end up in ~/Dropbox/apps/Desktoppr/ which, as you may have noted, is not where I keep my collection.

drxfh-2012-12-03-0206

Why not, you ask? Because there are many images that are in my collection that are personal photos, and I do not want to make them part of my Desktoppr library. You guessed it, anything I add to the Desktoppr folder goes back up to the site. You can see my collection online, once you login, at https://www.desktoppr.co/theconsultant

972fa8304265c4528873d40eac

For a while I would sync new images to Dropbox, then manually copy them across to the Wallpapers folder. This got tedious fast, so I worked for a while on cobbling a bit of a folder action script together. After messing around in Applescript for a day and not quite getting what I wanted, I headed over to Automator.

wallpaper-2481554-2012-12-28-0213

I created a new folder action and added the “Copy Finder Items” and chose my Wallpapers folder. Umm, that’s it. Too easy. Saved it, and then right click the Desktoppr folder and, in Services, go into Folder Actions, and add the workflow.

20410cc7eda936b47f103458df

Next time an image dropped into the Desktoppr folder it automagically got copied across. No more manual syncing.

Now I can spend all that extra time looking for the next great desktop picture!

b0bc3145225d99db362c014177