Archives
Admin / Logout

Adam Merrifield

a picture of me
I am a theme developer, a coder and internet personality.

what i am

I am the owner and operator of seyDoggy Systems, a small theme, code and design outfit based in Kitchener, Ontario, Canada. We primarily develop web based technologies but have begun to dabble in the desktop realm.

what i do

I code like a fool. I design like a fool. I am happiest when I can split my time between the two (though I tire of Photoshop faster then I do Sublime Text 2 or Terminal), and somehow I have managed to etch out a living doing so.

Trojan-Downloader:OSX/Flashback.I

F-Secure has provided a set of directions that’ll let you know if you have been infected. If you have the virus on your machine, F-Secure will walk you through the steps to remove the infection—Threat Description: Trojan-Downloader:OSX/Flashback.I.

| Trackback

codepoet / CUPS-PDF for Mac OS X

CUPS-PDF is a backend module for CUPSMac OS Xs printing system by Volker C. Behr that, rather than printing to a device, prints straight to PDF files.

via codepoet / CUPS-PDF for Mac OS X / wiki / Home — Bitbucket.

| Trackback

Access Linux from Mac OS X Finder

I run a Linux server in the house which I use for all sorts of things–a staging server, git server, backup and file server–all of which works well enough for me as a geek. But for the wife and kids, who are not into shell commands (for whatever reason), the server is of no use if they can’t use it via Finder.

For that there are two nifty packages that make browsing your Linux machine from an your mac as easy any other mac on the network. One package, called `netatalk` installs makes your Linux box AFP capable (Apple Filing Protocol), the other, called `avahi`, makes your Linux box discoverable, `bonjour` style.

I’ve been using these packages for a while now and until recently, setup has been sketchy and stability hasn’t been all that great. In recent months however, this has changed considerably and now both packages work (and work well) almost right out of the box. So here are some step-by-step instructions for making your Linux box discoverable and browsable by Mac computers on the network:

1. If you are on the Linux box, starr a shell, otherwise ssh into your Linux box.
2. Get the `netatalk` and `avahi` packages (check first to see that they’re not installed already).

$ sudo apt-get install netatalk avahi-daemon

3. Configure netatalk.

$ sudo vim /etc/netatalk/afpd.conf

Uncomment the default line or create your own parameter string (⇧G in VI will move the cursor to the end of the file).

- -tcp -noddp -uamlist uams_dhx.so,uams_dhx2.so -nosavepassword

4. [optional] Configure the volumes to share. By default netatalk sets some basic user privileges and directories to share. You can customize these to your liking.

$ sudo vim /etc/netatalk/AppleVolumes.default

5. Start the AFP and Bonjour services.

$ sudo /etc/init.d/netatalk restart ; # starts netatalk
$ sudo restart avahi-daemon ; # restarts avahi-daemon

Now look at Finder on your Mac and you’ll see your Linux box in the “Shared” list in the Finder sidebar.

For more on these two packages, visit the [Netatalk][] and [Avahi][] websites.

[Netatalk]: http://netatalk.sourceforge.net/
[Avahi]: http://avahi.org/

| Trackback

Installing Pear on OS X 10.7 Lion

Nothing big, just need to document this stuff or else I forget…

$ sudo cp /private/etc/php.ini.default /private/etc/php.ini
$ sudo php /usr/lib/php/install-pear-nozlib.phar
$ sudo pear config-set php_ini /private/etc/php.ini
$ sudo pecl config-set php_ini /private/etc/php.ini
$ sudo pear upgrade-all
| Trackback

Building a Micro Server – Part 1

building a micro server part 1 title image

You might recall a number of months back [I was working on repurposing an old iMac][a_100209211734] into a web server. I was doing this more because it could be done and not because I had to. Truth is I have two other servers which have more then enough head room to take on the additional, and somewhat minor load of web serving duties. But it was the challenge — or complete and utter geek indulgence — that drove me to waste spend my time making something of the old iMac G3.

However, the footprint of an iMac G3 (both physically and environmentally) is not ideal. You can’t rack mount an iMac G3, or stick it on a shelf or hide it under a desk… So I promptly ditched the idea and trumped it up as good bit of fun and some R&D.

But the bug for a smaller server had been planted… I was really liking the idea of a mini server that I could stow away under my desk (and not in a sound proof closet). Not just a web server, but a little *everything* server.

I had initially toyed with the idea of buying a Mac Mini for this but thought my wife would likely kill me for buying a new Mac as an experimental toy server while she continues to work from a PowerMac G4 (that happens to be dying a slow death). So I set about seeing what it would take to build my own micro server with all new parts that would approximate the Mac mini. Could it be done for less?

This is what I found (no affiliation):

* [1u micro server chassis][a_100209224857] – $79.99
* [mini server motherboard][a_100209225129] – $109.99
* [2.2GHz Dual-Core CPU][a_100209225613] – $51.99
* [1u 4 pin CPU fan][a_100209230228] – $47.00
* [2GB DDR2 SDRAM][a_100209225754] – $56.99
* [160GB HDD][a_100209230613] (optional as I had a few laying around) – $51.99

The total, if you include the hard drive, is $397.95 ($345.96 without hard drive). That’s more then $250 – $300 less then the Mac Mini. I know it’s a bit like comparing apples to oranges; the chip is slower, the bus is slower, the footprint is bigger and the I/O doesn’t really compare. On the flip side, the Mac mini doesn’t have a server grade power supply, is limited to slower laptop HDD’s and can’t be rack mounted. There are tradeoff’s either way but when I look at what I am hoping to use it for — web/file/media server — the differences will be outweighed by the 40% – 45% savings of the home built micro server.

This was enough for me, I was sold on the idea. If for nothing else then the pure geeky joy of it… so I went ahead and ordered the parts.

In part two I will show you the assembly of the micro server once the parts arrived, and some of the hiccups I had.

Read part 2

[tags]how to,server,mac mini[/tags]

[a_100209211734]: http://adam.merrifield.ca/2009/09/29/imac-g3-web-server-part-1/ “Adam Merrifield { the collective – the collective thoughts and web works of adam merrifield}”

[a_100209224857]: http://www.newegg.ca/Product/Product.aspx?Item=N82E16811152131 “Newegg.ca – SUPERMICRO CSE-502L-200B Black 1U Rackmount Mini Server Chassis for Intel Atom Platforms w/ 200W Power Supply – Server Chassis”

[a_100209225129]: http://www.newegg.ca/Product/Product.aspx?Item=N82E16813182168 “Newegg.ca – SUPERMICRO MBD-X7SLM-L-O LGA 775 Intel 945GC Micro ATX Intel Core 2 Duo/Pentium D/Pentium 4/Celeron D Server Motherboard – Server Motherboards”

[a_100209225613]: http://www.newegg.ca/Product/Product.aspx?Item=N82E16819116075&nm_mc=TEMC-RMA-Approvel&cm_mmc=TEMC-RMA-Approvel-_-Content-_-text-_- “Newegg.ca – Intel Celeron E1500 Conroe 2.2GHz 512KB L2 Cache LGA 775 65W Dual-Core Desktop Processor – Processors – Desktops”

[a_100209225754]: http://www.newegg.ca/Product/Product.aspx?Item=N82E16820146526&nm_mc=TEMC-RMA-Approvel&cm_mmc=TEMC-RMA-Approvel-_-Content-_-text-_- “Newegg.ca – Crucial 2GB (2 x 1GB) 240-Pin DDR2 SDRAM DDR2 667 (PC2 5300) Dual Channel Kit Desktop Memory Model CT2KIT12864AA667 – Desktop Memory”

[a_100209230228]: http://www.networksupply.ca/product/1455487/SNK-P0032A-4.html “Supermicro SNK-P0032A4 – processor cooler – 1U”

[a_100209230613]: http://www.newegg.ca/Product/Product.aspx?Item=N82E16822136112 “Newegg.ca – Western Digital Caviar Blue WD1600AAJB 160GB 7200 RPM 8MB Cache IDE Ultra ATA100 3.5" Internal Hard Drive -Bare Drive”

| Trackback

Turkey Rotini in Cream Sauce

### Shared by Adam Merrifield ###

Category: DinnerCuisine: Italian
Serves: 4

This is a delicious pasta dish that the whole family will love.

## Ingredients ##

* 0.4 kg ground turkey
* 284 ml Cream of Mushroom/Broccoli soup
* 1/2 cup white wine
* 1/2 cup cream/milk
* 5 cups rotini (whole wheat)
* 1 red pepper chopped
* 2 tsp minced garlic
* 1 cup Parmesan cheese (fresh grated)

## Directions ##

1. In a non-stick or seasoned cast-iron skillet, brown turkey over medium heat (about 4 minutes).
1. Add minced garlic and continue cooking for another 2 minutes.
1. Add the soup, wine and cream and reduce for about 15 minutes, stirring constantly.
1. Stir in chopped red peppers and continue cooking another 5 minutes.
1. Remove from heat and mix in Parmesan cheese. Let stand for 4 minutes.
1. Mix with cooked rotini and serve.

Search, share, and cook your recipes on Mac OS X with [SousChef](http://acaciatreesoftware.com/souschef/ “SousChef for Mac: Your Cooking Assistant (Acacia Tree Software)”)!

| Trackback

How AppleScript Saved My Address Book

From the time I got my iPhone — over a year and a half ago — I have been trying to force myself to use Apples own native products, like Mail, Address Book, iCal, etc… It was my thinking that this would make life easier, integrating into the whole Mac-iPhone way of life.

The thing is, I haven’t used any of these products since the days of OS X 10.2. For a time I was using ThunderMail (way back in the day) and eventually the whole Google Suite of apps like Gmail and Google Calendar. So a little over 1.5 years back, I started looking into the migration from these web services to the desktop apps that OS X provides.

With apps like [BusySync][a_091223104130] (and ultimately [BusyCal][a_091223104201] which I now use over iCal and in conjunction with Google Calendar), getting my calendar off the web but still having “anywhere” access was easy enough. And I did, for the first time ever, succumb to the .mac/mobileme world so my information is fully mobile and accessible to me in any form I choose. I am all about redundancy when it comes to data.

Since Mail and Gmail now do IMAP — and do it fairly well — getting local with my mail has not been difficult by any stretch, but I have to admit, I just don’t like the way Mail does things. I never have and that’s why I stopped using it so many years ago. I can get used to it though, and I am trying… on and off.

But my real reason why, after the better part of two years, I haven’t managed to fully integrate into the Macisphere way of doing things is none of the above… It has been moving contacts that has been the biggest catch.

I stopped using the Apple suite of apps around 2002-2003, so it goes without saying that the contacts acquired since then is quite extensive. Gmail’s way of collecting those contacts is sort of a drag-net approach — someone sends you an email and Gmail does it’s best to add that person to your contacts list… at all cost, with little regard for their name or whether it’s a duplicate. After this many years Gmail has collected what it thinks are 10,000 unique contacts… uhhh… yeah. And there is no way to manage those contacts in any practical manner.

So with a slew of free tools, exports, imports and lots of crying I was able to cram those 10,000 contacts into Address Book… which promptly rendered Address Book utterly useless. Fortunately Address Book comes with a handy command to look for duplicates (Card > Look for Duplicates…) and then merges them and their relevant data together. Great. After running for the better bit of 5 hours, Address Book was able to cut that down to a smidge over 4,500 contacts. While this made the app a little more useful on my Mac (though still really slow), Contacts on my iPhone was still, more or less useless.

And this is the way I’ve left it for the last 18 months. Defeated, deflated and frustrated.

Enter AppleScript. Why I hadn’t thought of this earlier, I have no idea, but just a few days ago, while writing an AppleScript to send out all my Christmas E-Cards (which invariably makes use of Mail and Address Book) I thought I had better do something about Address Book once and for all.

I knew going into this that Address Book was full of duplicate information, but it was different enough that Address Book wasn’t able to tell. For instance, if a contact has a first name of “John” and a last name of “Reynolds”, Address Book can’t draw the similarity from another contact with a dubious first name of “John Reynolds” and no last name. Nor can it conclude that the contact with the first name “Reynolds” and last name “John” is likely the same as the first contact.

In addition to this mass confusion, in Address Book’s attempt to manage duplicate contacts, it merged nameless email addresses into thousands of other nameless email addresses creating countless, nameless contacts, each with dozens, if not hundreds of emails… sound confusing?

It was time for some bug guns… big scripting, non-discriminating guns.

**Before I go any farther, let me start by saying DO NOT TRY THIS AT HOME! YOU WILL CAUSE IRREVERSIBLE CHANGES TO YOUR CONTACTS IN ADDRESS BOOK! Unless you are certain you have this information backed up or stored elsewhere, or unless you are just as desperate as me and don’t care anymore, do not use these scripts!!!**

## Delete Nameless Entries ##

So first things first. I want to get rid of all the nameless, kludged together contacts that resulted from Address Book compiling nameless, and therefor what it deemed to be duplicate, contacts. This is what I came up with:

tell application "Address Book"
		activate
		set thePeople to every person whose first name is missing value and last name is missing value
		repeat with i from 1 to count of thePeople
			set thePerson to (item i of thePeople)
			delete thePerson
			save
		end repeat
	end tell

[[get the up-to-date code snippet here][a_091223123541]]

AppleScript will tell Address Book to find all the contacts with no first or last name and delete them with no questions asked. If this scares you, DON’T USE IT. This cut down my contact list from 4,500+ to to about 2,300+. Good… better… but not great.

## Cleanup @ Entries ##

One thing I can’t stand is a contact with no proper name. You are nothing to me if all I have is your email address. It especially bothers me when a contact uses all or bits of their email address as the first and/or last name, like…

first name: john
middle name: @doe.
last name: com

or…

first name: [email protected]

So this next script looks for such contacts and indiscriminately wipes them out. If there is any question about whether the person really does have a proper first or last name, it will pause and ask… but for the most part it will just hack and slash with reckless abandon.

tell application "Address Book"
		activate
		set thePeople to (every person whose first name contains "@" or last name contains "@" or middle name contains "@")
		repeat with i from 1 to count of thePeople
			set thePerson to (item i of thePeople)
			set firstName to (first name of (item i of thePeople) as string)
			set lastName to (last name of (item i of thePeople) as string)
			set middleName to (middle name of (item i of thePeople) as string)
			set theirEmails to (value of email of (item i of thePeople) as string)
			set urlList to {"com", "net", "ca", "org", "uk", "us", "fr", "it", "edu", ".com", ".net", ".ca", ".org", ".uk", ".us", ".fr", ".it", ".edu"}

			if first name of (item i of thePeople) is missing value or last name of (item i of thePeople) is missing value then
				delete thePerson
			else if firstName contains "@" and lastName contains "@" then
				delete thePerson
			else if urlList contains lastName then
				delete thePerson
			else
				display dialog "first name: " & firstName & return & "middle name: " & middleName & return & "last name: " & lastName & return & return & theirEmails buttons {"Cancel", "KEEP", "DELETE"} default button "DELETE" giving up after 30
				copy result as list to {the buttonReturned, the gaveUp}
				if gaveUp is true then error number -128
				if buttonReturned is "Canceled" then error number -128
				if buttonReturned is "DELETE" then delete thePerson
			end if
			save
		end repeat
	end tell

[[get the up-to-date code snippet here][a_091223140548]]

## Detect Name Switch ##

The next step was to sort out how many contacts were actually duplicates, only with their first and last names reversed. It’s understandable that Address Book would think such entries were unique, but you’d think the error was common enough that it would have such provisions built in and at least ask you to review what it suspects might be duplicates. Since Address Book does nothing of the sort, I had to write an AppleScript that does.

The script is too long and complex show it all here, but basically what happens is AppleScript tells address book to look for contacts whose first and last names match those contacts whose last and first names are the same. It then prompts me with the comparative information and asks me to decide if they are in fact the same. If yes, then it asks me which one, if any, that I want to delete.

This process cut another several hundred more contacts from my list.

[[get the up-to-date code snippet here][a_091223131712]]

## Split First Name ##

Something else I found regularly when going through my contacts is entires where both the first and last name would be in the first name field and the last name field entry left empty. This would also produce a lot of undetectable duplicates as the comparison of `first name: John Doe` to `first name: John, last name: doe` would obviously yield two unique contacts.

This script will search for contacts whose first names contain a space and whose last name is not present. Going on the assumption that the first and last name are both contained in the first name (hence the space), the script takes the first word and the last word and uses them for a proper first and last name. Again, it does so rather blindly, so this contact `first name: Royal Bank of Canada` will become `first name: Royal, last Name: Canada`. I need not say this again… proceed with caution.

tell application "Address Book"
		(*
		set first name to first word in first name
		set last name to last word in first name
		*)
		set the thePeople to (every person whose (last name is missing value and first name contains " "))
		repeat with i from 1 to count of thePeople
			set theirName to (first name of (item i of thePeople))
			set firstName to (first word of theirName)
			set lastName to (last word of theirName)
			set properties of (item i of thePeople) to {first name:firstName, last name:lastName}

			set newFirstName to (first name of (item i of thePeople))
			set newLastName to (last name of (item i of thePeople))
			save
		end repeat
	end tell

This process, when combined with another duplicate search from the Address Book card menu, managed to chop out another 500 contacts.

[[get the up-to-date code snippet here][a_091223143806]]

## And the Winner Is? ##

After beating Address Book over the head with these scripts various times and after running Address Books own duplicate check after each script run I was able to cut my number of contacts from Gmail’s initial 10,000, down to 4,500+ until finally I managed to walk away from the whole fight with a clean, organized Address Book containing 1,308 cards! Ahhh… victory!

So does this make me a happy user of the Apple office apps? It’s certainly got me closer. Now that I have an Address Book that is usable, I’m now using Mail on both the desktop and iPhone and am making a real effort to get used to them both.

[a_091223104130]: http://www.busymac.com/ “BusyCal – Share Calendars on a LAN and sync with Google Calendar”
[a_091223104201]: http://www.busymac.com/ “BusyCal – Share Calendars on a LAN and sync with Google Calendar”
[a_091223123541]: http://www.codecollector.net/view/669E7C12-D9B6-4DF0-8E7D-D5DDCC101D2F “Code Collector – View Snippet”
[a_091223131712]: http://www.codecollector.net/view/F982AFBA-5105-4132-9EEC-3C7126A31DC2 “Code Collector – View Snippet”
[a_091223140548]: http://www.codecollector.net/view/5EA33012-40A6-4A24-AC6D-F08701E09529 “Code Collector – View Snippet”
[a_091223143806]: http://www.codecollector.net/view/9EA02C2E-98EF-4C46-9A51-47A126EAE7E9 “Code Collector – View Snippet”

| Trackback

Apple Baked Oatmeal

Shared by rbngndl

Category: Breakfast

 

Ingredients

  1. 1 C home made applesauce with cinnamon/sugar
  2. 3/4 C brown sugar
  3. 1/2 c white sugar
  4. 4 eggs
  5. 6 C quick oats
  6. 4 tsp baking powder
  7. 1 tsp salt and cinnamon
  8. 1 tsp cinnmon or 1/2 cinnamon and 1/2 apple pie spice
  9. 2 C milk
  10. 2 apples peeled and chopped (I like granny smith)
  11. 2 C coconut
  12. 1 -2 C craisins or raisins
  13. 1/2 C chopped walnuts or pecans

Directions

  1. Beat together 1st four ingredients. Add remaining, mix well. Add apples, coconut, craisins last. Sprinkle nuts on top and pour into greased 9 x 13 and cover and refrigerate overnight. Remove from refrigerator while you preheat the oven. Or go ahead and bake at 350 for about 45 minutes or until center is set.

Search, share, and cook your recipes on Mac OS X with SousChef!

[tags]breakfast,apple,oatmeal,recipe[/tags]

| Trackback

3 Quick AppleScripts to Save You Time

AppleScript is an automation solution that allows you to handle tasks quickly and efficiently without a lot of thought or effort on your part. This can be repetitive *things* you may want to take care of in short order or this might simply be *stuff* you want to do from anywhere regardless of what app you are in. Whatever the case, AppleScript can usually be employed for such tasks.

I enjoy solving process streamlining needs on my own with AppleScript and I am not one to keep good things to myself so here are just 3 little scripts I would like to share. You might have a use for them and they might just make your day easier.

## Toggle apps on or off ##

If you’re like me you might have one or two apps that do all that you need them to just by turning them on or off. So why leave them running in the background all the time? Two apps that I can think of in my list are [Nocturne][btn] and [Isolator][wmi]. I use them from time to time but not often enough to keep them in the menu bar permanently. Activating their features requires me to select their icon from the menu bar and selecting the option that toggles their behavior on or off. Or if you just leave their behavior toggled on then quit and restart the app, it has the exact same effect. Quitting the app turns the feature off (obviously) and starting the app turns the feature on…

Sounds like a job for AppleScript:

– replace “YourAppName” with your app
set yourApp to “YourAppName”

– leave the rest to us
if appIsRunning(yourApp) then
tell application yourApp to quit
else
tell application yourApp to activate
end if

on appIsRunning(appName)
tell application “System Events” to ¬
(name of processes) contains appName
end appIsRunning

By changing the name of “YourAppName” to the app you want to toggle on or off and then setting yourself a keyboard shortcut for the script, you can then activate the app and it’s only desired feature with a stroke of the keys.

### Download ###

Get your fresh copy of “[On-Off_AppToggle][ooat]” from CodeCollector.net

[btn]: http://code.google.com/p/blacktree-nocturne/ “blacktree-nocturne – Project Hosting on Google Code”
[wmi]: http://willmore.eu/software/isolator/ “Isolator”
[ooat]: http://www.codecollector.net/view/CD71C6B3-F52E-4040-AF95-2BE9F9668827 “Code Collector – View Snippet”

## Simple Web Search ##

Google Web Search AppleScriptDo you remember when a query to a search engine was a simple string that looked like `http://www.google.com/search?q=this%20or%20that`? Now-a-days search strings tend to include all sorts of information like the source of the search, encoding, language, client, OS… and ends up like and unreadable bunch of garbage like this `http://www.google.com/search?source=qsb-mac&oe=UTF-8&hl=en&q=this%20or%20that&client=qsb-mac&ie=UTF-8`. I for one don’t need every one of my queries to be counted so I wrote a simple script to pose that basic string once again. For your own purposes you can change the search engine and browser to suit your needs.

set userQuery to text returned of ¬
(display dialog “Google search:” ¬
default answer “” buttons {“Cancel”, “OK”} ¬
default button 2)

set httpArray to ¬
{“http://”, “www.”, “.com”, “.ca”, “.net”, “.org”, “.info”, “.us”}

set httpBool to false
repeat with httpAny in httpArray
if userQuery contains httpAny then
set httpBool to true
exit repeat
end if
end repeat

if httpBool then
tell application “Safari” to open location userQuery
else
tell application “Safari” to open location ¬
“http://www.google.com/search?q=” & userQuery
end if
tell application “Safari” to activate

When you launch this script you just enter your search query and press return.

### Edits ###

**r4 10-29-09 09:43** – It would be handy if you could use this script to open known urls to, so I’ve edited the script to do so in a basic manner. It’s not perfect yet as I need to write some regular expressions to really detect proper TLDs and such. But it will do for now. So, perform a query and Safari will open that query in as a Google search. Or, enter a URL and Safari will directly open that website.

### Download ###

Get your fresh copy of “[Google_Search][gs]” from CodeCollector.net

[gs]: http://www.codecollector.net/view/969C4A3D-C59F-400C-94D5-A26B4DE2DB20 “Code Collector – View Snippet”

## Launch apps by task ##

Launch Task AppsMy days, weeks and even months can often be broken into many different tasks. I wear a lot of hats as a small business owner. One day I might be providing support for the RapidWeaver themes I make and the next day I will be knee deep in code making the latest greatest product. One minute I am social networking and the next I am designing something shiny.

Each of these tasks involves a unique set of apps to be open which can make changing gears a time consuming — if not confusing — process.

To address this I wrote a script that launches (or quits) a particular set of apps based on the task I need to do. For example:

* If I am busy with support, I want to launch:
* Mailplane
* Safari
* TextMate
* If I am networking I will use:
* Safari
* Adium
* LimeChat
* Mailplane
* TweetDeck
* If I am designing I want:
* DigitalColor Meter
* LittleSnapper
* Photoshop
* Or if I am developing a new theme:
* RapidWeaver
* Safari
* TextMate
* MAMP

And so on… As mentioned, I can use the script to either launch these sets of apps or quit them and I can do so with a single keyboard-shortcut. This saves a lot of time and helps keep the clutter to a minimum. You can fill in your own task sets and your own apps to suit.

– define the sorts of tasks you wish to activate multiple apps for
set taskArray to {“Surfing”, “Media”, “Designing”}

set taskName to ¬
{choose from list taskArray with prompt ¬
“Pick your process:”} ¬
as string
set toDoArray to {“Launch apps”, “Quit apps”}
set toDoResult to ¬
{choose from list toDoArray with prompt ¬
“Would you like to launch or quit these applications?”} ¬
as string

if taskName is equal to “Surfing” then

– define the apps you would like to open/close
set appArray to ¬
{“Safari”, “LittleSnapper”, “Mail”}

runTrue(appArray,toDoResult)
else if taskName is “Media” then

– define the apps you would like to open/close
set appArray to ¬
{“iTunes”, “Last.fm”, “DVD Player”}

runTrue(appArray,toDoResult)
else if taskName is “Designing” then

– define the apps you would like to open/close
set appArray to ¬
{“Adobe Photoshop CS3″, “DigitalColor Meter”, “LittleSnapper”}

runTrue(appArray,toDoResult)
else
display dialog ¬
“Something is wrong! Please check your array values.”
end if

– runTrue function
on runTrue(appArray,toDoResult)
repeat with appName in appArray
if toDoResult is “Launch apps” then
tell application appName to activate
else if toDoResult is “Quit apps” then
tell application appName to quit
else
display dialog “Houston, we have a problem!”
end if
end repeat
end runTrue

### Download ###

Get your fresh copy of “[LaunchTaskApps][lta]” from CodeCollector.net

[lta]: http://www.codecollector.net/view/7882/LaunchTaskApps “Code Collector – View Snippet”

## Go play ##

I hope you can make use of these scripts in your own daily workflow. I know I would be lost without them. Do have any scripts of your own you want to share? Feel free to comment and let me know.

[tags]applescript,app toggle,launch task apps, google search[/tags]

| Trackback

Scripting LittleSnapper… Slight Return

Less then a week after writing [*this*][sls] AppleScript — which launches [LittleSnapper][ls] and snaps the website currently in view in Safari — the boys at Realmac Software come out with [*this bookmarklet*][bml] that does exactly the same thing, only with a mouse-click instead of a hot-key combination… unless you’re me.

I loath the mouse and if I can avoid ever using it I will go to great lengths to make sure my hands stay firmly atop my keyboard. Perhaps you’re the same way, so for kicks I turned Realmac Software’s bookmarklet into an executable AppleScript that I can assign a hot-key to.

## What’s a bookmarklet? ##

First you have to understand what a bookmarklet does. A bookmarklet is nothing more then a bit of javascript (in many cases) that when clicked performs a basic task. It’s like a mini application… like an applet… in fact, it *is* an applet, hence the name “bookmark”-”let”. In the case of the LittleSnapper bookmarklet, clicking the bookmark (or URL) tells your browser (in javascript) to change the URL in the address bar from `http://example.com` to `littlesnapper://snap/http://example.com`. You’re just adding `littlesnapper://snap/` to the front of any URL! You can actually do this yourself, provided you have LittleSnapper. Try going your favorite website, click the address field, type `littlesnapper://snap/` in front of the URL and hit return… ta-da!

## Make one-click easier? ##

So let’s go back to actually using the bookmarklet… you have to click on it and that’s no fun. It’s time to turn it into AppleScript!

The bookmarklet, if you look at it in your bookmarks folder, looks like this:

javascript:location.href=’littlesnapper://snap/’+location.href;

The quick and dirty way to turn this into an executable AppleScript would be to use Safari’s built in `do JavaScript` method, like this:

tell application “Safari”
do JavaScript “location.href=’littlesnapper://snap/’\n
+location.href;” in document 1
end tell

But that would leave you pretty much locked into using the script with Safari when using hot-keys, while *clicking* the bookmarklet will work in any browser. So `do JavaScript` is too limiting.

Since we only need to pass in the string `littlesnapper://snap/` before the URL, why not just write a method that does that:

tell application “Safari”
set currentURL to URL of front document
open location “littlesnapper://snap/” & currentURL
end tell

This works, but if you want to apply it to all other browsers — Opera, Camino, Firefox, etc — you have a lot of work ahead of you as you discover the various degrees of scriptability each app has. To grab the URL in some of these apps you have to jump through hoops:

* in safari it’s `URL of front document`
* for Firefox `«class curl» of window 1` will sometimes work
* Camino is `URL of browser window 1` and so on…

Some apps need to use System Events to access them, others don’t. And then try and tell each one that you want to `open location`, again with or without System Events… it turns into argument soup very quickly.

A good rule of thumb when trying to script anything is to simplify the number of tasks you assign to any given process. In this case, for each browser I am trying to do two things; get the current URL and then open a new, modified URL.

## LittleSnapper is a browser too! ##

Then it got me thinking — LittleSnapper uses webkit as it’s rendering engine and therefor it should share a lot of the same scripting dictionary that Safari uses. So I thought I would test something out; I attempted to `open location “littlesnapper://snap…` with LittleSnapper itself:

set currentURL to “http://www.google.ca”
tell application “LittleSnapper”
open location “littlesnapper://snap/” & currentURL
end tell

Viola! Without opening a “browser”, I just snapped a web shot of Google.ca, right in LittleSnapper. This now cuts the workload of running unique scripts for each browser in half since I can now tell LittleSnapper to open the URL… once I have it.

## Scripting a common thread ##

So now to get the URL from the browser — any browser — without making a code spaghetti like this mess:

if application “Firefox”is running then
tell application “Firefox”
set currentURL to «class curl» of window 1
end tell
else if application “Safari”is running then
tell application “Safari”
set currentURL to URL of front document
end tell
else if application “Opera”is running then
tell application “Opera”
set props to GetWindowInfo of window 1
set currentURL to item 1 of props
end tell
else if application “Camino”is running then
tell application “Camino”
set currentURL to URL of window 1
end tell
end if

There has to be a better way… and there is. Here comes System Events to the rescue with a couple of keystroke executions like so:

tell application “System Events”
– highlight address field with ⌘L
keystroke “l” using {command down}

– copy to clipboard with ⌘C
keystroke “c” using {command down}
end tell

This will allow us to access any browser the same way, with global hot-keys as executed by AppleScript.

Now we just need to talk to those browsers to find out which one is in use. We can do this with an if statement, like this:

if application “Safari” is running then
tell application “System Events”
keystroke “l” using {command down}
keystroke “c” using {command down}
end tell
end if

But with four or more browsers this would be a bit much.

## The full deal ##

So let’s make an array out of our favorite browsers, run that array through a loop, mash in our System Event keystrokes, and finish it all off with a variable passed into LittleSnapper and this is what we get:

– let’s define our array
set appArray to {“Safari”, “Firefox”, “Opera”, “Camino”}

– then run that array through a loop
repeat with appName in appArray
if application appName is running then
tell application appName to activate
tell application “System Events”
keystroke “l” using {command down}
keystroke “c” using {command down}
end tell
delay 0.5

– make a variable from the clipboard
set currentURL to the clipboard
end if
end repeat

– pass that variable in to LittleSnapper
tell application “LittleSnapper”
activate
open location “littlesnapper://snap/” & currentURL
end tell

Is this overkill to get a hot-key combo that does what a bookmarklet does in one click? Depends on who you ask I guess. I think it’s a pretty good solution in fact. Now instead of copying a bookmarklet to the toolbar of every browser I use, I have a script that I can assign a global hot-key to (via [FastScripts][fs] or some such tool) and use it across any browser I set in my array.

Yes, I am *that* much of a geek.

## Download ##

[Get it fresh from CodeCollector.net][ccdn2]

[tags]applescript,littlesnapper,realmac,software,safari,firefox,opera,camino,browser,bookmarklet,hot-key[/tags]

[sls]: http://www.seydoggy.com/2009/09/30/scripting-littlesnapper/ “seyDoggy Web and Graphic Design – seyDoggy weblog – my thoughts on the web and the mac”
[ls]: http://www.realmacsoftware.com/littlesnapper/ “LittleSnapper – Screenshot and Website Capture for Mac OS X Leopard”
[bml]: http://www.realmacsoftware.com/blog/index_files/littlesnapper-bookmarklet.php “Realmac Software Blog – RapidWeaver and LittleSnapper News”
[fs]: http://www.red-sweater.com/fastscripts/ “FastScripts”
[ccdn2]: http://www.codecollector.net/view/E8CE65D6-67B3-45DF-A3E5-745F9616F1B3 “Download from CodeCollector.net”

| Trackback
Powered by RapidWeaver, WP-Blog and WordPress 3.5.1