Work around Outlook4Mac bug -- AppleScript to open file when its name is highlighted

Sleiman

Registered
Greetings readers,

Microsoft released a few days ago the long-awaited (by me) Service Pack 2 for Office for Mac 2011 but unfortunately SP2 doesn't fix some critical (for me) limitation of the software: unlike the Windows version one cannot attach files to appointments, tasks or contact records. This is a critical limitation that inhibited me from using Outlook on Mac as I have a lot of documents attached to records of the mentioned types.

But I am determined to do the switch from PC to Mac so I am looking for ways to work around the mentioned limitation. So I thought this: I change the appointment, contact and tasks records (in my Outlook on Windows) that include attachments by saving the attachment in a special folder then replace it in these records with just the file name.

Later when I do the switch to Outlook for Mac and I open, say, an appointment that should include an attachment but instead just includes the filename, I highlight the file name then press a combination of keys that activates an Apple Script which takes the highlighted text and searches for a file with that name in a special folder. If the file is found it is opened (otherwise a message is displayed accordingly).

I am pretty sure this can be done as I get the impression that AppleScript is quite powerful.

Does anyone know how this is done / have a script that does it?

Thanks a lot!

Sleiman
 
Any idea why this doesn't work?

set filepath to POSIX path of "Users:Sleiman:Documents:-- My Email Attachments:" & selection

set command to "open " & quoted form of filepath
do shell script command

I get the error message:
error "Can’t make insertion point after character 167 of text of document \"OpenMyFile.scpt\" into type Unicode text." number -1700 from insertion point after character 167 of text of document "OpenMyFile.scpt" to Unicode text

Cheers,
Sleiman
 
I was able to solve this problem by copying (in AppleScript) the selected text to the clipboard and now it works:

------------------
tell application "System Events"
keystroke "c" using command down
end tell
set myFilename to the clipboard as Unicode text

set filepath to POSIX path of "Users:Sleiman:Documents:-- My Email Attachments:" & myFilename

set command to "open " & quoted form of filepath
do shell script command
------------------

The downside of this solution is that previous clipboard contents are lost. Is there any way I can get the selected text as a string without having to copy it into the clipboard?

A command such as...

set myFilename to selection as Unicode text

... didn't work. Any ideas?

Actually, the mentioned solution -- with copying to the clipboard -- doesn't work 100%. The script when it runs looks for the previous highlighted text and not the current. Any idea why?

Thanks!

Sleiman
 
With AppleScript, I'm not sure of a clean way to get the selected text. With Automator, however, it's easy.

Open Automator and select File > New > Service. The default should be "receives selected text in any application". You can change it to just Outlook.

From there you could pass that text into an AppleScript to do further processing, or do everything within automator itself. The great thing about Automator is that it integrates well with all kinds of scripting methods.

I too have tried the "simulate command-C" approach, and have found that it's necessary to perform checks to be sure the clipboard content has changes, and wait for it, because sometimes there is a delay. Keep in mind that this is happening asynchronously; your script has no way of knowing what command-C is supposed to do or how long it will take to actually copy the text. It just simulates the keystroke and continues on. If Outlook takes half a second to copy the text, your script might have already finished running in that time. So annoying!

This is why I wouldn't recommend relying on this method if it's avoidable. Automator services are cleaner.
 
Back
Top