Tuesday, 30 April 2013

Adding copy-to-clipboard rollovers in Contacts app via AppleScript

Adding Copy to Clipboard Rollovers in Contacts App via AppleScriptApple's Contacts app includes a lot of great shortcuts for initiating different forms of communication. Just click an email address, phone number or URL field label to display a list of available options. You can send an email, show a phone number in large type or start a FaceTime call, for example. Curiously, one shortcut that's absent from most of these popups is one for copying the email address, phone number, URL, etc. to the clipboard. Mailing addresses are one exception, as they provide an option to copy a mailing label. But, other fields don't include this option. Sure, you could just select a phone number, email address, URL, etc., and press Command+C to copy it. But, what fun is that? It sure would be nice if there were just more handy copy-to-clipboard shortcuts instead. With the help of AppleScript, you can add your own. Here's how...

Writing the Script

The following steps demonstrate how to add a Copy to Clipboard shortcut to phone number fields in the Contacts app. If you have any trouble following along, you can download the complete script here, along with ones for email address and URL fields too.

1. Launch AppleScript Editor (in /Applications/Utilities)

2. Create a new script document and enter the following code:

-- "using terms from" is necessary to let AppleScript know that these event handlers are terminology that belongs to the Contacts app
using terms from application "Contacts"
-- This handler returns the Contacts property for which the plug-in should function
on action property
return "phone"
end action property
-- This handler returns the name of the plug-in to be displayed in the Contacts property popup menu
on action title
return "Copy to Clipboard"
end action title
-- This handler basically tells the Contacts app that this plug-in should be enabled for a given person
on should enable action with theProperty for thePerson
if theProperty is not equal to missing value then
return true
else
return false
end if
end should enable action
-- This handler runs when the plug-in is selected from the Contacts property popup menu
on perform action with theProperty for thePerson
-- Target the contact from where the plug-in was triggered
tell application "Contacts"
-- Retrieve the value of the property that triggered the plug-in
set theValue to value of theProperty
end tell
-- Copy the value to the clipboard
set the clipboard to theValue
end perform action
end using terms from

Note: If you want to create a version of this script for email address or URL fields, just change the action property handler to return the appropriate field type, i.e.,

on action property
return "email"
end action property

or...

on action property
return "url"
end action property

Installing and Using the Script

In order for the script you created to appear in the Contacts app, it needs to be saved in the proper place.

1. Quit Contacts if it's running.

2. Save the script you created as Contacts > Copy Phone to Clipboard.scpt, in script format, into the ~/Library/Address Book Plug-Ins folder in your Home directory. If this folder doesn't already exist, go ahead and create it.

Adding Copy to Clipboard Rollovers in Contacts App via AppleScript

Now, just relaunch the Contacts app. When you click on a phone number field label, you should see a new option for copying the phone number to the clipboard. Now, repeat the steps above for email addresses and URLs to enhance the Contacts app even further.

Adding Copy to Clipboard Rollovers in Contacts App via AppleScript

This marks my last scheduled post for the TUAW for a bit. Hopefully, you'll see more of me here in the future. In the meantime, feel free to reach out to me on Twitter to say "Hello," ask a scripting question or two, suggest a future topic, etc. Until next time, Happy Scripting!

Adding copy-to-clipboard rollovers in Contacts app via AppleScript originally appeared on TUAW - The Unofficial Apple Weblog on Mon, 29 Apr 2013 07:00:00 EST. Please see our terms for use of feeds.

Permalink | Email this | Comments

Source: http://www.tuaw.com/2013/04/29/adding-copy-to-clipboard-rollovers-in-contacts-app-via-applescri/

auto sport medical rehab

No comments:

Post a Comment