AppleScript to rename files revisited

A couple years back I blogged a script that would take a file and append the name of the enclosing folder to the beginning of the file name. For example, a file called “Testfile.txt” inside a folder called “Folderstuff” would be renamed to “Folderstuff Testfile.txt.”

A reader recently stumbled across that script and asked:

That script is exactly what I’ve been looking for, with one exception:

When saved as an application I can’t drag and drop multiple files onto it. In fact, it doesn’t seem to be able to handle multiple files at all, I just get errors.

I’ve done a bunch of searching on how to deal with multiple files but I just cant seem to make it work.

Here are some updated versions of the original script. This first one is meant to be run directly out of Script Editor on whatever files you have selected in the Finder.


tell application "Finder"
set theFiles to selection
set theCount to number of items in theFiles
repeat with i from 1 to theCount
set theFile to (item i of theFiles as text)
set TheName to name of (theFile as alias)
set thePath to POSIX path of (theFile as alias)
set parentFolderPath to text 1 thru ((offset of TheName in thePath) - 2) of
thePath
set AppleScript's text item delimiters to "/"
set parentFolder to (item -1 of text items of parentFolderPath) as string
set NewName to (parentFolder & " " & TheName)
set name of file theFile to NewName
end repeat
end tell

And this version is meant to be saved as an AppleScript applet. Drop some files (not a folder on it) and it’ll run with it.


on open theFiles
set theCount to number of items in theFiles
repeat with i from 1 to theCount
tell application "Finder"
set theFile to (item i of theFiles as text)
set TheName to name of (theFile as alias)
set thePath to POSIX path of (theFile as alias)
set parentFolderPath to text 1 thru ((offset of TheName in thePath) - 2)
of thePath
set AppleScript's text item delimiters to "/"
set parentFolder to (item -1 of text items of parentFolderPath) as string
set NewName to (parentFolder & " " & TheName)
set name of file theFile to NewName
end tell
end repeat
end open

UPDATE 2008-06-13: Reader Andrew pointed out that the script only grabs the title of the front window and won’t work if you’re in list view and have a expansion triangle open. I’ve updated the scripts to account for that.

Tagged! Seven songs and seven blogs

Ned Raggett tags me with the following blog meme that’s been making the rounds:

“List seven songs you are into right now. No matter what the genre, whether they have words, or even if they’re not any good, but they must be songs you’re really enjoying now, shaping your spring. Post these instructions in your blog along with your 7 songs. Then tag 7 other people to see what they’re listening to.”

So here we go…

1. Edith Nylon – “Edith Nylon”
1979 French new wave with all of the requisite elements for fantastic new wave: shouty vocals, insistent bass/drums, a synthesizer that does nothing else except announce it’s presence, a guitar line good enough to carry the whole song, vague title/band name reference to synthetic material (think Plastique Bertrand, Poly Styrene, The Age Of Plastic, etc.). Sometimes attitude is indeed good enough.

2. Swervedriver – “Duel”
I fished out Raise and Mezcal Head once word of the reunion tour leaked out and I revise my earlier estimate. “Duel” is now objectively 72% more awesome than I originally remember it being (originally I had this pegged at 62% more awesome when the Juggernaut Rides compilation was released two years back). And for me, Swerve is the kind of band that deserves to be measured in units of “awesome!” “Duel” is my favorite song of theirs by far – you think it’s going one way and then it shifts into another song and then back again. Bonus points for the chiming major-key guitar riff during the “I’m going down, down to the marketplace” chorus. (Video from last month’s show here in LA)

3. Motörhead – “We Are The Road Crew (instrumental)”
A couple months back I stumbled across the VH-1 Classic Albums episode on Ace Of Spades. No further word is necessary here, but there’s an extra from the DVD that made it onto YouTube – a semi-reunion (Clarke is in a different studio and effectively pasted in here) of the Lemmy, Clarke, and Taylor line-up who blast through “We Are The Road Crew” as an instrumental.

4. The Long Blondes – “Nostalgia”
Couples has a bucket full of “difficult second album” clichés, but when I saw them last week they are as furious live as Hanley/Scanlon-era Fall. Obvious pick would be the skittery Can-meets-P.I.L. “Round The Hairpin” but I’m going with “Nostalgia.” This is to 2008 what the Yeah Yeah Yeahs’ “Maps” was to 2004. At least it should be.

5. Bo Diddley – “I Don’t Like You”
This 5:25 clip is as important to civilization as the discovery of fire, but the first thing I thought of was this track from the utterly insane The Black Gladiator album where Bo reconstitutes himself as a Sly Stone-style funk monster (Dave Alvin’s “The Night Bo Diddley Banned The Beat” is far more instructive rememberance than any of the other pieces last week). The Beat isn’t here, but Bo summons up a wailing howl worthy of Screaming Jay Hawkins before launching into a raunchy version of Booker T. & The MGs.

6. Orchestral Manoeuvres In The Dark – “Radio Waves”
Yes I did just pick up the new reissue of this. Uncomfortably sandwiched in between their New Wave singles and subsequent John Hughes pop, Dazzle Ships was the outsider album of 1983. “Radio Waves” is the best combination of collapsing circuity and flat out new wave, but you’re never really sure which part of the song is going to take the lead. Producer Rhett Davies should get a little credit for egging OMD on with this. He produced all those Brian Eno albums as well as The B-52’s Wild Planet and Dazzle Ships is the best possible amalgamation of that. Still my most favorite Peter Saville album cover too.

7. Holly & The Italians – “Rock Against Romance”
It’s a fantastically great song. Skip ahead to the 2:40 mark here and go nuts.

That’s it. I’m tagging these folks to carry on the meme.

Phoenix Mars Lander

phoenix_marsview.jpg Congratulations everyone! Our Martian robot population increases by one. The Bad Astronomy guy (via Making Light) beats his chest for the humans a little loud, so I have to add my own experience in here.

During the landing I was at a pretty substantial bar-be-que party. I’m holding my phone (tuned into the Mars coverage) in one hand, cradling my beer with the other hand, and I’m outside watching a band play. In some sort of sartorial self-realization I concluded that “hey, the future is pretty cool after all.”

That parachute photo is pretty fantastic though.


Also fantastic is this photo from NASA Watch. Devon Island is an arctic island where several research groups have been operating because it’s considered to be a pretty good analog to Mars. I’ll say it is!

mars_devonisland.jpg

R.I.P. Robert Asprin

asprin_myth.jpgR.I.P.

On May 22, 2008, Bob passed away quietly in his home in New Orleans, LA. He had been in good spirits and working on several new projects, and was set to be the Guest of Honor at a major science fiction convention that very weekend. He is survived by his mother, his sister, his daughter and his son, and his cat, Princess, not to mention countless friends and fans and numerous legendary fictional characters.

He will be greatly missed.

Indeed. I stopped reading the Myth books somewhere around book eight or nine, but they were (and still are) among my favorite things to read when I’m ill – especially those old Starblaze editions with the goofy Foglio art. I ran across them the same year that The Hitchhiker’s Guide To The Galaxy was impacting and quickly absorbed the lot into the nerd zeitgeist I was developing for myself at age fifteen (Steve Jackson’s micro games, Apple II assembly language, Tempest/Missile Command, and Raiders Of The Lost Ark being the other big cornerstones)

Cat and mouse blamed for Albanian blackout

I’ve been fascinated by Albania for years. OK, so it gets made fun of often, and stories like this aren’t helping. I can’t help laughing though…

Cat and mouse blamed for blackout

Albanians may have found a new villain to blame for the frequent power cuts that have been blighting their lives.

The country’s main electricity company says a cat chasing a mouse caused a 72-hour blackout in parts of the capital, Tirana.

The animals ran into an area of high-voltage cables and were electrocuted, a spokeswoman for the firm – Kesh – told Reuters news agency.

“We took pictures because we’ve never had anything like this,” she said.

Power cuts have been endemic in Albania for many years.

The authorities usually blame drought and the dilapidated state of the communist-era grid, which appears to be buckling under the strain of the extra demand caused by the Albanians’ recent access to modern amenities.

Eastern Europe’s favorite cat and mouse team was apparently unavailable for comment.

The mall with the strange device, Excelsior!

excelsior_americana_longfellow.jpg

After picking fights with irate self-absorbed dog owners, I finally decided to check out the Americana in Glendale. My honorary title of Captain Obvious only permits me to offer up one comment: Yup, it’s a shopping mall. Still, it’s a shopping mall that’s fully 21st century buzzword compliant. Walking around the place you can easily visualize the individual layers in every engineering drawing of the place. Here’s the implicit “public space.” “Luxury condos” up here. A marinade of “new urbanism” over there. A blanket mist of “mixed use” over the whole area. If that doesn’t make the point for you then the ear-splitting background music will certainly enforce it. I’m serious here – the Americana’s background muzak is set to somewhere between “stun” and “kill.”

The Americana is eye pleasing, but not terribly different from the Grove, Santana Row, or any other kind of downtown redevelopment that skips around the “Olde Towne” prefix. The old Glendale Galleria is still there of course – cast aside to the back of the driveway like a hulking old beater car that’s been replaced by spiffy retrofuture-mobile.

The ads and the ambient branding for the Excelsior condos remind me way too much of the Longfellow poem “Excelsior.” In the poem, Longfellow describes a young man passing through a town on his way up into the mountains. His only possession, a banner with the words “Excelsior.” The locals warn him anyway from the dangerous mountain pass, but the young man ignores them and continues his climb until eventually he is found frozen to death in the snow, still grasping “the banner with the strange device, Excelsior!”

The poem describes a young man passing through a town bearing the banner “Excelsior” (translated from Latin as “ever higher”, also loosely but more widely as “onward and upward”), ignoring all warnings, climbing higher until inevitably, “lifeless, but beautiful” he is found by the “faithful hound” half-buried in the snow, “still clasping in his hands of ice that banner with the strange device, Excelsior!”

Irony Department on the phone? Perhaps. I do wonder about the wisdom of opening luxury shopping malls in economic uncertainty. The press release fanfare piles on the Tinker Bell clapping. Still, I keep picturing the Americana – dead empty except for some graffiti on the Excelsior sales office.

There, in the twilight cold and gray,
Lifeless, but beautiful, he lay,
And from the sky, serene and far,
A voice fell, like a falling star,
Excelsior!

excelsior_thurber.jpg

What I did with my $600 from the government

mbv_tickets.jpg

Forget any of that “spend it on the economy” malarkey, I contributed some of it to the Irish-American Drone Rock Reunion Fund and the rest on our own 2008 travel fund.

Cthulhu knows how this is all going to turn out. The online fever pitch going into these shows is matched only by Kevin and co.’s secrecy. Apparently Papal elections are easier to get into than MBV rehearsals.

24 or so Flickrs per second

Going against the tide of Flickr curmedgeons, here’s some Flickr video from the QC archives:

Alkali flies on the ground at Mono Lake. They don’t bite at all, but it’s unnerving walking around them and seeing them flee and reorient as you walk around.

Some Mono Lake shoreline to go along with the flies.

A flyby of the last remaining Northrop Flying Wing prototype.