Tuesday, August 11, 2009

Arguing with AppleScript

AppleScript sounds great: it's a high-level language, and the code, done right, can be quite human-readable. That's also the problem ... there are so many cases where "to" and "of" both work, and then you run into a case where it matters. Frustrating! That makes me long for a less-flexible language; if there's only one way to issue the command, look it up, use it, and you're done. Or try to figure out where and why AppleScript is so slippery ...

Anyway, yesterday's quest was to identify special folders, like the Applications folder, without assuming /Applications.

Most of the names of special folders are listed in the AppleScript Language Guide: Commands Reference. Yay! However, some special folders aren't there. You can find that longer list in AppleScript 1-2-3. For instance, I used this line of AppleScript

set removePlugin to (the path to "cmnu" as string) & "SyncpCMPlugin.plugin" as alias

where the path to "cmnu" gives me the path to the user's Contextual Menu Items folder. That's not as readable as I'd like my AppleScript, but there's no human-readable version of the 4-letter code.

Today's challenge is to discover if the Trash is empty or not with AppleScript; I'm not going to cheat and use shell.

I've tried

set trashItems to the count of every item in the trash

set number_of_items to (count (every item of the trash))

set tryThis to count of items in trash

and they don't work.

Oh yeah, here's what I mean about AppleScript being a slippery dog, and natural language failing.

These lines work:

tell application "Finder" to set trashList to (items of trash)

tell application "Finder" to open (the path to the trash folder as alias)

These lines do not work:

tell application "Finder" to set trashList to (items of trash folder) with Can't get every item of trash folder.

tell application "Finder" to open the trash

Since Unix is so good at text manipulation, I find that aspect of AppleScript frustrating, and the Working with Text AppleScript reference useful.

OK, so I have solved today's AppleScript frustration to see if the Trash is empty or full.

set trashList to {""}

set trashFiles to {""}

tell application "Finder" to set trashList to (the items of the trash)

tell application "Finder" to set trashFiles to the name of the items in the trash

set old_delimiters to AppleScript's text item delimiters

set AppleScript's text item delimiters to {", "}

set display_trashFiles to trashFiles as string

set trashCount to the count of trashFiles

if (trashFiles is {}) then

display dialog "There are no items in the Trash." buttons {"OK"} default button 1 with title "Trash Empty" with icon note

else

display dialog "There are items in the Trash." buttons {"OK"} default button "OK" with title "Trash Not Empty" with icon caution

end if

if trashCount > 1 then

display dialog "There are " & trashCount & " items in the Trash." & return & "list: " & (trashFiles as string) buttons {"OK"} default button "OK" with title "Trash Full" with icon stop

else if trashCount = 1 then

display dialog "There is " & trashCount & " item in the Trash." & return & "list: " & display_trashFiles buttons {"OK"} default button "OK" with title "Trash Full" with icon caution

else

display dialog "Empty, " & trashCount & " items in the Trash." & return & "list: " & display_trashFiles

end if

set AppleScript's text item delimiters to old_delimiters

tell application "Finder"

display dialog "What would you like to do?" buttons {"Empty Trash", "View Trash", "OK"} default button "Empty Trash" with icon note

if button returned of result is "Empty Trash" then

empty trash

else if button returned of result is "View Trash" then

open the (path to the trash folder as alias)

end if

end tell

That was harder than I expected, but now it's done.

Sunday, August 9, 2009

AppCleaner

Just found where that annoying preference was hiding with AppCleaner, since of course Spotlight doesn't want to search there ... even if you don't want to delete an application, what AppCleaner finds when you're frustrated can still be valuable!

Dropbox passes!

Unlike Syncplicity (dropping Mac support, failing most of Backup Bouncer), Dropbox passes Backup Bouncer!

sudo /usr/local/bin/rsync -aAHNX --delete --fileflags /Volumes/Src/ ~/Dropbox/bb/

sudo ./bbouncer verify -d /Volumes/Src/ /Users/hope/Dropbox/bb/

Verifying: basic-permissions ... ok (Critical)

Verifying: timestamps ... ok (Critical)

Verifying: symlinks ... ok (Critical)

Verifying: symlink-ownership ... ok

Verifying: hardlinks ... ok (Important)

Verifying: resource-forks ...

Sub-test: on files ... ok (Critical)

Sub-test: on hardlinked files ... ok (Important)

Verifying: finder-flags ... ok (Critical)

Verifying: finder-locks ... ok

Verifying: creation-date ... ok

Verifying: bsd-flags ... ok

Verifying: extended-attrs ...

Sub-test: on files ... ok (Important)

Sub-test: on directories ... ok (Important)

Sub-test: on symlinks ... ok

Verifying: access-control-lists ...

Sub-test: on files ... ok (Important)

Sub-test: on dirs ... ok (Important)

Verifying: fifo ... ok

Verifying: devices ... ok

Verifying: combo-tests ...

Sub-test: xattrs + rsrc forks ... ok

Sub-test: lots of metadata ... ok

That's a clean slate for rsync 3.0.6 (patched) and for Dropbox (provisionally)! Nice to know Dropbox should keep my OpenMeta tags intact. At work tomorrow, we'll see if Dropbox still passes, on the other end of the Dropbox wormhole; that will be the real test of Dropbox.

UPDATE: Not surprisingly, Dropbox doesn't look as pretty on the other side of the wormhole. It mostly fails everything, so only use it for self-contained files (no extended attributes, no specialized metadata, no resource forks; just timestamps and bsd-flags).

sudo ./bbouncer create-vol Src

./bbouncer create /Volumes/Src

sudo ./bbouncer verify -d /Volumes/Src ~/Dropbox/bb

Verifying: basic-permissions ... FAIL (Critical)

Verifying: timestamps ... ok (Critical)

Verifying: symlinks ... FAIL (Critical)

Verifying: symlink-ownership ... FAIL

Verifying: hardlinks ... FAIL (Important)

Verifying: resource-forks ...

Sub-test: on files ... FAIL (Critical)

Sub-test: on hardlinked files ... FAIL (Important)

Verifying: finder-flags ... FAIL (Critical)

Verifying: finder-locks ... FAIL

Verifying: creation-date ... FAIL

Verifying: bsd-flags ... ok

Verifying: extended-attrs ...

Sub-test: on files ... FAIL (Important)

Sub-test: on directories ... FAIL (Important)

Sub-test: on symlinks ... FAIL

Verifying: access-control-lists ...

Sub-test: on files ... FAIL (Important)

Sub-test: on dirs ... FAIL (Important)

Verifying: fifo ... FAIL

Verifying: devices ... FAIL

Verifying: combo-tests ...

Sub-test: xattrs + rsrc forks ... FAIL

Sub-test: lots of metadata ... FAIL

sudo ./bbouncer verify -d /Volumes/Src ~/Dropbox/bb | grep ok

Verifying: timestamps ... ok (Critical)

Verifying: bsd-flags ... ok

./bbouncer clean /Volumes/Src

./bbouncer clean ~/Dropbox/bb

So ... be careful. On the origin end, your file is fine; on the other end of the wormhole, it might be mangled.

Synology and extended attributes

Past time to run Backup Bouncer on my Synology store-everything plan!

./bbouncer create-vol Src

./bbouncer create /Volumes/Src

sudo /usr/local/bin/rsync -aAHNX --delete --stats /Volumes/Src/ /Volumes/NetworkShare/Dst-rsync1

Number of files: 69

Number of files transferred: 26

sent 4621 bytes received 655 bytes 2110.40 bytes/sec

total size is 365 speedup is 0.07

rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1039) [sender=3.0.6]

sudo ./bbouncer verify -d /Volumes/Src /Volumes/NetworkShare/Dst-rsync1

Verifying: basic-permissions ... FAIL (Critical)

Verifying: timestamps ... stat: ./some-file: stat: No such file or directory

FAIL (Critical)

Verifying: symlinks ... ok (Critical)

Verifying: symlink-ownership ... FAIL

Verifying: hardlinks ... stat: link1: stat: No such file or directory

stat: link2: stat: No such file or directory

stat: link3: stat: No such file or directory

FAIL (Important)

Verifying: resource-forks ...

grep: ./some-file/rsrc: Not a directory

Sub-test: on files ... FAIL (Critical)

Sub-test: on hardlinked files ... FAIL (Important)

Verifying: finder-flags ... ok (Critical)

Verifying: finder-locks ... FAIL

Verifying: creation-date ... ok

Verifying: bsd-flags ... ok

Verifying: extended-attrs ...

Sub-test: on files ... FAIL (Important)

Sub-test: on directories ... FAIL (Important)

Sub-test: on symlinks ... FAIL

Verifying: access-control-lists ...

Sub-test: on files ... FAIL (Important)

Sub-test: on dirs ... FAIL (Important)

Verifying: fifo ... FAIL

Verifying: devices ... FAIL

Verifying: combo-tests ...

Sub-test: xattrs + rsrc forks ... FAIL

Sub-test: lots of metadata ... FAIL

sudo /usr/local/bin/rsync -aAHNX --delete --fileflags --force-change --stats /Volumes/Src/ /Volumes/NetworkShare/Dst-rsync2

Number of files: 69

Number of files transferred: 26

sent 4664 bytes received 655 bytes 2127.60 bytes/sec

total size is 365 speedup is 0.07

rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1039) [sender=3.0.6]

sudo ./bbouncer verify -d /Volumes/Src /Volumes/NetworkShare/Dst-rsync2

Verifying: basic-permissions ... FAIL (Critical)

Verifying: timestamps ... stat: ./some-file: stat: No such file or directory

FAIL (Critical)

Verifying: symlinks ... ok (Critical)

Verifying: symlink-ownership ... FAIL

Verifying: hardlinks ... stat: link1: stat: No such file or directory

stat: link2: stat: No such file or directory

stat: link3: stat: No such file or directory

FAIL (Important)

Verifying: resource-forks ...

grep: ./some-file/rsrc: Not a directory

Sub-test: on files ... FAIL (Critical)

Sub-test: on hardlinked files ... FAIL (Important)

Verifying: finder-flags ... ok (Critical)

Verifying: finder-locks ... ok

Verifying: creation-date ... ok

Verifying: bsd-flags ... ok

Verifying: extended-attrs ...

Sub-test: on files ... FAIL (Important)

Sub-test: on directories ... FAIL (Important)

Sub-test: on symlinks ... FAIL

Verifying: access-control-lists ...

Sub-test: on files ... FAIL (Important)

Sub-test: on dirs ... FAIL (Important)

Verifying: fifo ... FAIL

Verifying: devices ... FAIL

Verifying: combo-tests ...

Sub-test: xattrs + rsrc forks ... FAIL

Sub-test: lots of metadata ... FAIL

One thing to note is that I need --fileflags with rsync to pass the finder-locks test; other than that the two rsync results look the same. Without the errors, those results are:

Verifying: basic-permissions ... FAIL (Critical)

Verifying: timestamps ... FAIL (Critical)

Verifying: symlinks ... ok (Critical)

Verifying: symlink-ownership ... FAIL

Verifying: hardlinks ... FAIL (Important)

Verifying: resource-forks ...

Sub-test: on files ... FAIL (Critical)

Sub-test: on hardlinked files ... FAIL (Important)

Verifying: finder-flags ... ok (Critical)

Verifying: finder-locks ... ok

Verifying: creation-date ... ok

Verifying: bsd-flags ... ok

Verifying: extended-attrs ...

Sub-test: on files ... FAIL (Important)

Sub-test: on directories ... FAIL (Important)

Sub-test: on symlinks ... FAIL

Verifying: access-control-lists ...

Sub-test: on files ... FAIL (Important)

Sub-test: on dirs ... FAIL (Important)

Verifying: fifo ... FAIL

Verifying: devices ... FAIL

Verifying: combo-tests ...

Sub-test: xattrs + rsrc forks ... FAIL

Sub-test: lots of metadata ... FAIL

Or, paring it down to failed tests,

Verifying: basic-permissions ... FAIL (Critical)

Verifying: timestamps ... FAIL (Critical)

Verifying: symlink-ownership ... FAIL

Verifying: hardlinks ... FAIL (Important)

Verifying: resource-forks ...

Sub-test: on files ... FAIL (Critical)

Sub-test: on hardlinked files ... FAIL (Important)

Verifying: extended-attrs ...

Sub-test: on files ... FAIL (Important)

Sub-test: on directories ... FAIL (Important)

Sub-test: on symlinks ... FAIL

Verifying: access-control-lists ...

Sub-test: on files ... FAIL (Important)

Sub-test: on dirs ... FAIL (Important)

Verifying: fifo ... FAIL

Verifying: devices ... FAIL

Verifying: combo-tests ...

Sub-test: xattrs + rsrc forks ... FAIL

Sub-test: lots of metadata ... FAIL

The NetworkShare volume is a Synology RS-407 running an embedded Linux mounted via AFP (AppleShare). The permission problems (and ownership and hardlinks and resource forks and ACLs) might be how it's mounted, but I'm concerned about those extended attributes. Might be time to ask Google and friends ...

Tuesday, August 4, 2009

Endnote v. Zotero

From Thomson Reuters Lawsuit Dismissed blog post at The Quintessence of Ham:

I'm delighted to announce that this morning the Fairfax Circuit Court dismissed the lawsuit filed against Zotero by Thomson Reuters. The lawsuit had claimed that the Center for History and New Media "reverse-engineered" Thomson Reuters’s EndNote software to provide data interoperability between Zotero and EndNote.

I used EndNote at work around 1990 to manage our scientific references. I personally used EndNote in the early 1990s when I scored a free copy for being helpful in the right place at the right time. I loved it for bibliography management and formatting! I thought it could have stored more/better/any notes on each reference to help the writing process, but still very useful. At the same time, I was concerned about the company's ethics. I couldn't put my finger on it, but I wasn't sure I liked the company (I read the EULA). The fact that they filed this lawsuit helps me articulate my hesitation. Why should I be locked in to their format? Thank goodness for the web! You can use Zotero or RefWorks (not free, but I have a site license at work) or CiteULike or Connotea or Memento.

From those choices, I would recommend Zotero because it's very good as a bibliography manager (I don't need to create bibliographies now, so I don't have an opinion on that). It even includes the note taking features I wanted in EndNote years ago! It just makes sense to me to store the notes with the reference; that's what will help you (remember to) make the correct citation.

It's also a great note-taking tool for anything on the web, web notebook, web snapshot archiver, whatever you want to call this category. So you could probably use Zotero instead of another Firefox add-on like ScrapBook+ or even a service like Iterasi.

The beta version has sync. I'm not sure how I would use Zotero's Timeline support (maybe if you track news reports on certain topics?), but Timeline is very cool! Many plugins. It's impressive, and even more impressive that it doesn't feel bloated. [This sounds like a gush. Guess what? I don't use it often, but I'm glad it's there, and when I sync my Profile, I get my Zotero data too.] I guess the real drawback to Zotero is that it requires Firefox and I like Safari and Cruz too.

But my point is, I'm glad the big guy (EndNote, established software with corporate funding) didn't get to take out the little guy (Zotero, university project) this time.

End of Syncplicity

I finally sent a bug report to Syncplicity to help them improve the Mac client, and their reply was that they no longer support Macs. Time to look for an alternative! Luckily I gave up on the USB-thumb-drive-rsync that caused me to use Syncplicity in the first place and went back to Firewire-micro-hard-drive-rsync (it's older, but lasts longer, probably because USB flash drives aren't made for many write cycles, and just plain works) so I don't have the same urgent need to keep certain files synchronized between home and work MacBook Pros.

Conveniently enough, Lifehacker has an Online Storage Feature-by-Feature Comparison Chart for the services that have a free trial. Since I especially like the sync between two Macs, that narrows the field down immediately to two: Dropbox and Mozy. I suppose it doesn't have to be a sync so much as an automatic upload when I change certain pre-determined files.

So, browsing lifehacker ... Mozy has that enterprise aura of respectability (I have to look for that in software at work, so it's second nature to notice it when it appears). Dropbox is looking like the standard by which to judge others. And don't forget the newcomer (to free trials) SugarSync! And the gDrive should be coming soon, too.

Mozy or Dropbox? Mozy is cheaper to add more online storage space, but I don't use much since rsync to Firewire is fast and easy. I think it comes down to how I plan to use it: Mozy aims at backups (so compare to rsync.net) and Dropbox aims at sync (so I have common files readily accessible even if I forget my travel drive). So I guess Dropbox wins the toss.

Saturday, August 1, 2009

Thanks, Chex!

Cale ate all of his Rice Chex, one of the few ready-made cereals that's free of all his allergies, so we put it on the shopping list. At the grocery store this morning, we noticed that all of the Chex flavors, except wheat obviously, are now gluten-free! Hurrah for them! Cale and I agree that corn chex has more flavor, too!