The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniFocus Extras (http://forums.omnigroup.com/forumdisplay.php?f=44)
-   -   Text entered in AppleScript prompt getting converted to some Asian characters (http://forums.omnigroup.com/showthread.php?t=30081)

johnnydaboy 2013-06-20 10:31 AM

Text entered in AppleScript prompt getting converted to some Asian characters
 
I am using Mail Act-On with Apple Mail to send emails to my OmniFocus inbox. I use a key command (courtesy of Mail Act-On) to fire off a series of actions, one of which is to run an AppleScript.

I have been using a modified "Send to OmniFocus" AppleScript and it has been working well, but it can only take the subject of the selected email and put it in the title of the OmniFocus item.

I want to be able to [B]change[/B] the title of the item before it is added to OmniFocus, so I modified the script a bit to display a dialog into which I can enter a different title for the item.

Everything works great [B]except[/B] that the text that is entered somehow gets converted to Asian characters and so is totally unreadable by mono-lingual little old me.

I can't imagine why this could be happening, but then, I'm an AppleScript novice. So, I turn to you and ask, "what's wrong with this picture?"

[CODE]using terms from application "Mail"
on perform mail action with messages theMessages
tell application "Mail"

repeat with eachMessage in theMessages
set theStart to missing value
set theDue to missing value

set theTitle to the subject of eachMessage
set theNotes to the content of eachMessage
set theSender to sender of eachMessage

set itemTitle to theTitle

-- Display dialog to allow user to specify the Title for the new OmniFocus Inbox item
try
set itemTitle to display dialog "Item title" buttons {"Cancel", "Save"} default button "Save" cancel button "Cancel" default answer (theTitle)
on error number -128
set userCanceled to true
end try

set theCombinedBody to "Created from message:%3C" & message id of eachMessage & "%3E" & return & "From: " & theSender & return & return & theNotes

tell application "OmniFocus"
tell default document
set newTaskProps to {name:itemTitle}
-- if theStart is not missing value then set newTaskProps to newTaskProps & {start date:theStart}
-- if theDue is not missing value then set newTaskProps to newTaskProps & {due date:theDue}
if theCombinedBody is not missing value then set newTaskProps to newTaskProps & {note:theCombinedBody}

set newTask to make new inbox task with properties newTaskProps
end tell
end tell
end repeat
end tell
end perform mail action with messages
end using terms from

[/CODE]

I don't know if you need Mail Act-On to even test this, but any suggestions as to why this might be happening (or even better, a solution) would be most appreciated!

Thx

johnnydaboy 2013-06-23 05:57 AM

Solution to above... would love to know if you find this useful
 
Solution found. Is this useful? How could it be improved?

[CODE]using terms from application "Mail"
on perform mail action with messages theMessages
tell application "Mail"

repeat with eachMessage in theMessages
set theStart to missing value
set theDue to missing value

set theTitle to the subject of eachMessage
set theNotes to the content of eachMessage
set theSender to sender of eachMessage

try
set itemTitle to the text returned of (display dialog "Item title" buttons {"Cancel", "Save"} default button "Save" cancel button "Cancel" default answer theTitle)
on error number -128
set userCanceled to true
end try

set theCombinedBody to "Created from message:%3C" & message id of eachMessage & "%3E" & return & "From: " & theSender & return & return & theNotes

tell application "OmniFocus"
tell default document
set newTaskProps to {name:itemTitle}
-- if theStart is not missing value then set newTaskProps to newTaskProps & {start date:theStart}
-- if theDue is not missing value then set newTaskProps to newTaskProps & {due date:theDue}
if theCombinedBody is not missing value then set newTaskProps to newTaskProps & {note:theCombinedBody}

set newTask to make new inbox task with properties newTaskProps
end tell
end tell
end repeat
end tell
end perform mail action with messages
end using terms from
[/CODE]

Here is the finished script: [url]http://bit.ly/11xwgfM[/url]

Put it in ~/Library/Application Scripts/com.apple.mail/

I was having some problems getting the Mail Act-On rules to all work within a single rule, so at their suggestion I've broken the actions into who separate rules to move the message and then run the script.

[B]Step 1[/B] Runs the applescript then calls the second rule
[IMG]https://dl.dropboxusercontent.com/u/10537595/Step%201.png[/IMG]

[B]Step 2[/B] Files the message in an Action mailbox
[IMG]https://dl.dropboxusercontent.com/u/10537595/Step%202.png[/IMG]


All times are GMT -8. The time now is 04:49 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.