Hi,
I’m a fairly ignorant scripter who “assembled” and adjusted some scripts mined from messages in this forum by Jim Baskins (10/9/2000) and ideas from SpamReporter Version 1.5 (5/5/2002) created by Maury McCown to create a script that will:
- Export selected Entourage 2004 email messages to a location
- Activate a Spam Reporting Application
- Process email messages at the location (refresh message list in the program and processes all in list)
- Return to the Entourage
And it worked fine for the past year through several 10.3 updates.
But after I upgraded to 10.4 the Spam processing step broke (figures, it’s script I wrote myself):
- The Spam program activates
- But doesn’t refresh or process it’s message list after becoming active
- Entourage 2004 doesn’t return as the front most app but complains “behind the scenes”
with the following error:
System Events got an error:
NSReceiverEvaluationScriptError:4
Anyone know what might have changed?
The relevant code to the steps that no longer work is in the last lines in my script below,
I’m assuming the click button commands or the window identification variable are now a problem, but don’t know what to correct them with.
tell application "Sp@mXMacintosh"
-- Launch SpamXMacintosh or make it the active application
activate
end tell
tell application "System Events"
tell process "Sp@mXMacintosh"
-- refresh the message list and process all messages
-- the variable 'spamx' identifies the window name of the program (currently '4.2.4')
click button "Refresh" of window spamx
click button "All" of window spamx
end tell
end tell
Any help would be greatly appreciated.
Lyle
Model: Mac Desktop G4 (AGP Graphics)
AppleScript: Script Editor 2.1
Browser: Safari 412.5
Operating System: Mac OS X (10.4)
I don’t have access to the application SpamXMacintosh and there was not a demo on their site. Without the application or info about its dictionary, helping with a script is pretty tough There is a tool on Apple’s website- UIElementINspector.app- that will help identify the correct object description/hierarchy of different interface elements. There are also some example scripts available on that url. UI scripting in OS X has evolved with each major system release, so what was working in interface scripting OS X 10.1 in 2001 may not be correct in 10.3 or 10.4.
Could you post the full script? You reference other parts of the script in your comments that could be involved with your error.
Here’s the link to the inspector app: http://www.apple.com/applescript/uiscripting/02.html
Craig
Thanks,
I downloaded and this is what I found when i mouse over the open window of Sp@mX:
<AXApplication: “Sp@mXMacintosh”>
<AXWindow: “Sp@mX 4.2.4”>
Attributes:
AXRole: “AXUnknown”
AXRoleDescription: “unknown”
AXParent: “<AXWindow: “Sp@mX 4.2.4”>”
AXWindow: “<AXWindow: “Sp@mX 4.2.4”>”
AXTopLevelUIElement: “<AXWindow: “Sp@mX 4.2.4”>”
AXPosition: “x=10 y=50”
AXSize: “w=608 h=336”
AXEnabled: “1”
Also, here’s the whole script (edited out my personal path info)
If you see anything, let me know.
THanks!
-- Suggest you save your compiled applescipt with filename:
-- Sp@mX \cX.scpt
-- Note: "\cX" provides a 'control-x' keyboard shortcut in Entourage
-- The following code is adapted from a message written by Jim Baskins (10/9/2000) and also includes ideas from SpamReporter Version 1.5 (5/5/2002) created by Maury McCown © 2002.
-- This Script:
-- 1. quits SpamXMacintosh if it is running
-- 2. saves selected messages from Microsoft Entourage 2004 to a designated file folder on your hard drive in the Entourage format (2001 and vX have not been tested. See maxLength below)
-- 3. removes possible problem characters : / . \
-- 4. checks for duplicate names before saving
-- 5. displays error messages if Entourage incounters them
-- 6. then re-launches SpamXMacintosh to ensure the messge list is refreshed.
global ccode, tcode, folderPath, maxLength, spamx
set ccode to "OPIM" -- file creator code
set tcode to "M822" -- file type code
set spamx to "Sp@mX 4.2.4" -- current version of Sp@mX
set folderPath to "HardDisk:Users:MyAccount:SPAM:"
-- MODIFY! full path name to finder folder where you will save your messages (i.e., "disk:Users:folder:")
set maxLength to 128
-- MODIFY! maximum length of saved file name (not including extention)
-- ¢ In OS X maxLength should not exceed 251
-- ¢ In OS 9 maxLength should not exceed 27
set deleteMessage to false
-- "true" deletes selected mail messages after saving them to 'folderPath' Otherwise set to "false".
tell application "Microsoft Entourage"
-- Save messages selected in Microsoft Entourage to the folder specified in folderPath and delete them from Entourage if 'deleteMessage' option is set to 'true'(also remove invalid characters from file names and avoid duplicates)
activate
try
set cm to current messages
if cm is equal to {} then error "No messages selected."
repeat with aMsg in cm
set t to source of aMsg
set sub to subject of aMsg
tell me to writefile(t, sub)
if deleteMessage then
delete cm
end if
end repeat
on error theErr
display dialog theErr
end try
end tell
on OffsetInList(theItem, theList)
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to return
set theText to theList as text
set AppleScript's text item delimiters to tid
set theCharOffset to offset of theItem in theText
set theParOffset to count of paragraphs in (characters 1 thru theCharOffset of theText as text)
return theParOffset
end OffsetInList
on writefile(s, subj)
try
tell application "Finder" to activate
set fileName to makeName(subj)
set fileRef to open for access (file (folderPath & fileName)) with write permission
write s to fileRef
close access fileRef
tell application "Finder"
activate
set the file type of file (folderPath & fileName) to tcode
set the creator type of file (folderPath & fileName) to ccode
end tell
on error theErr
display dialog theErr
end try
end writefile
on makeName(str)
try
set str to remove(":", str)
set str to remove("/", str)
set str to remove(".", str)
set str to remove("\\", str)
if ((count str) = 0) then set str to "temp" -- fix blank subject lines
set str to str & ".eml"
if ((count str) > maxLength) then set str to text 1 thru maxLength of str
set nameOK to testFile(folderPath & str)
if not nameOK then
set str to text 1 thru -3 of str
repeat with i from 1 to 99
set newstr to str & i
set nameOK to testFile(folderPath & newstr)
if nameOK then exit repeat
end repeat
set str to newstr
end if
set temp to str
return temp
on error theErr
display dialog theErr
end try
end makeName
on testFile(aPath)
-- See if file exists
set nameOK to false
try
get file (aPath)
on error
set nameOK to true
end try
return nameOK
end testFile
on remove(char, str)
-- remove all char from str
set od to AppleScript's text item delimiters
set AppleScript's text item delimiters to char
set temp to text items of str
set AppleScript's text item delimiters to ""
set temp to temp as text
set AppleScript's text item delimiters to od
return temp
end remove
tell application "Sp@mXMacintosh"
-- Launch SpamXMacintosh or make it the active application
activate
end tell
tell application "System Events"
tell process "Sp@mXMacintosh"
-- refresh the Message list and process all messages
click button "Refresh" of window spamx
click button "All" of window spamx
end tell
end tell
Oh, OH Ohhhhhhhhh … duh.
Ok, got it. It works fine. Stupid user error.
I’d forgotten "Access for assistive devices’ had to be turned on for the script to work.
Thanks for pointing out the UI inspector. Since it needs universal Access turned on to use it - it was fixed then.
Anyway, if you see anything of interest or bizarre in my script, feel free to comment.