Outlook script not working, error: to item 1 of result

At least Get Selected Outlook Items action of Automator works or not? If it works, I can show how to resolve the problem. Try this:

  1. Open Automator.
  2. Choose [b]“Create Quick Action” /b
  3. Drag to right area of window the action Get Selected Outlook Items
  4. Drag to right area of window the action Run AppleScript. Left it as is.
  5. Go to “File” menu and save service as “Get Selected Outlook Items”.

Now try following. Returns it selected Outlook items or not? :


set thePath to "" & (path to library folder from user domain) & "Services:Get Selected Outlook Items.workflow"

do shell script "/usr/bin/automator '" & POSIX path of thePath & "'"

@KniazidisR - Sadly this action “Get Selected Outlook Items” seems not available and missing in Automator on my system with the newest Outlook for Mac (Version 16.49). Only “Get Selected Mail Items” is available.

This means that the new Outlook is an inferior product, a surrogate. It is written for the Mac with no AppleScript support or service support. I just don’t buy it. Sorry you already spent on a bad product.

You are absolutely right there, no argument here :slight_smile: :wink: never the less many of us stuck with it for work reasons.

Apple Script support is a requested feature for Outlook For Mac here: https://outlook.uservoice.com/forums/924856-the-new-outlook-for-mac/suggestions/39253423-support-applescript It is possible that they will bring Apple Script back, but who knows, they don’t seem in a rush and it’s Microsoft.

Actually, I like Apple’s Mail.app better. So far, it suffers from a lack of automation for exporting messages as PDF

Therefore, before better times came, I wrote a script for myself here using the minimal GUI code (important for the longevity of the solution). 3 clicks only. Select message, run this:


-- Mail.app part (load remote content, open message, get its subject)
tell application "Mail"
	activate
	set download html attachments to true -- load remote content as well
	set aMessage to item 1 of (get selection)
	set theSubject to subject of aMessage
	open aMessage
end tell

-- replace every ":" symbol in theSubject with "_"
set {ATID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ":"}
set {itemList, AppleScript's text item delimiters} to {text items of theSubject, "_"}
set {theSubject, AppleScript's text item delimiters} to {itemList as text, ATID}

-- build destination file's HFS path
set theFile to (((path to desktop folder) as text) & theSubject & ".pdf")

-- GUI scripting part (3 clicks)
tell application "System Events" to tell application process "Mail"
	click menu item "Print…" of menu 1 of menu bar item "File" of menu bar 1
	repeat until menu button "PDF" of sheet 1 of window 1 exists
		delay 0.2
	end repeat
	click menu button "PDF" of sheet 1 of window 1
	click menu item "Open in Preview" of menu 1 of menu button "PDF" of sheet 1 of window 1
end tell

-- Preview.app part (save as pdf)
tell application "Preview"
	repeat until document 1 exists
		delay 0.2
	end repeat
	save document 1 in file theFile
	quit
end tell

-- Mail.app part (close message's window)
tell application "Mail" to close window 1

Here is version without using Preview.app. But its GUI part contains 5 operations: 3 clicks, 1 setting textfield value, and 1 keystroke:


-- Mail.app part (load remote content, open message, get its subject)
tell application "Mail"
	activate
	set download html attachments to true -- load remote content as well
	set aMessage to item 1 of (get selection)
	set theSubject to subject of aMessage
	open aMessage
end tell

-- replace every ":" symbol in theSubject with "_"
set {ATID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ":"}
set {itemList, AppleScript's text item delimiters} to {text items of theSubject, "_"}
set {theSubject, AppleScript's text item delimiters} to {itemList as text, ATID}

-- build destination file's Posix path
set theFile to ((POSIX path of (path to desktop folder) as text) & theSubject & ".pdf")

-- GUI scripting part (3 clicks, 1 textfield value setting, 1 keystroke)
tell application "System Events" to tell application process "Mail"
	click menu item "Export as PDF…" of menu 1 of menu bar item "File" of menu bar 1
	repeat until text field 1 of sheet 1 of window 1 exists
		delay 0.2
	end repeat
	keystroke "g" using {shift down, command down}
	repeat until combo box 1 of sheet 1 of sheet 1 of window 1 exists
		delay 0.2
	end repeat
	set value of combo box 1 of sheet 1 of sheet 1 of window 1 to theFile
	click UI element "Go" of sheet 1 of sheet 1 of window 1
	repeat while combo box 1 of sheet 1 of sheet 1 of window 1 exists
		delay 0.2
	end repeat
	repeat until sheet 1 of window 1 exists
		delay 0.2
	end repeat
	click UI element "Save" of sheet 1 of window 1
end tell

-- Mail.app part (close message's window)
tell application "Mail" to close windows

The current version of MSO (16.49) still has AppleScript support. JavaScript and Objective-C have been added. In contrast, the Automator Actions have been removed since Office 2016. The old ones (from previous installations) still ran as long as it is a 32-bit system.

See: https://answers.microsoft.com/en-us/msoffice/forum/msoffice_officeinsider-mso_mac-msoinsider_outlook/office-2019-and-365-does-applescript-still-work/1171b81e-47ce-4432-aaaa-3051d2f4b62b

I can not say how it works, because I do not use Outlook.

Yes, I already rated 1 out of 5 there answers from people at Microsoft. For lack of zero.