Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Applescript compile fails with "Expected end of line, etc. but found identifier"

Hi,


I've written my first applescript to move messages in Micorosoft Outlook to a specific folder. It is based on existing scripts I found on the internet. However my version keeps failing to compile with the error "Expected end of line, etc. but found identifier". I tried the exact same script on another Mac and it works. I created a very simple version of the script to show the error. All I am trying to do is get the current selected messages so I can move them:


on run {}

tell application "Microsoft Outlook"

set selectedMessages to current messages

end tell

end run


and I still get the same errors on the word "messages" above.


MAC is running OSX 10.9.4

Microsoft Outlook for Mac 2011 - version 14.4.3 (140616)


Since the script works on other computers the only thing I can assume is something wrong with the setup.


Any help is greatly appreciated.

- Ben


User uploaded file

Posted on Aug 22, 2014 7:00 PM

Reply
17 replies

Aug 23, 2014 7:16 AM in response to shamsian

The problem is that the word current is being seen as a variable and not as something Outlook is understanding. So Applescript expects the line to be


set variable1 to variable2


with nothing coming after variable2.


When you said you tried this on another system and it worked did you copy this script over or did you enter it on the other system? As a first try I would copy the script from the working system to this one and see if it works. You could also copy this one over to the other system and see if it fails.


It is also possible that the version of Outlook you have on this system does not understand the word 'current'. Look in the dictionary entry for Outlook and see if 'current' is in the dictionary.

Aug 23, 2014 7:29 AM in response to shamsian

Unfortunately with the new software running this site it is not possible to paste in Applescripts and keep the syntax coloring so i have to do an image capture


This is what your compiled script should look like. If the indentation is not the same or the coloring of the words is different then you have made an error in inputting the code.

User uploaded file

Notice how in the above current is purple and in yours it is green (the color variables are set to)


on run {}

  tell application "Microsoft Outlook"
       set selectedMessages to current messages
  end tell

end run


If you copy and paste the above into a new editor window and compile sit it should appear as the screen shot above

Aug 24, 2014 7:24 PM in response to Frank Caggiano

Frank Caggiano wrote:


twtwtw


Any reason that the parens would be needed on some cases and not in others? As you can see the code the OP posted compiled fine on my system with no need of the parens. Also the OP mentioned that the code did work on one machine but not another so I would assume again the parens were not needed in that case.


JUst curious


regards


Parentheses have the same function here as they do in mathematical equations. They are cues to the compiler about the order in which different parts of the statement should be processed. The problem here, I think, is that the word current is part of a lot of applescript nouns: current date, current application, current messages, current user, current track, current location, etc. That's exacerbated by the fact that message is also a noun in its own right in Outlook, creating an ambiguous bit of grammar. Applescript has to interpret the presence of that word in context, and several factors - different versions of the OS or of the relevant applications, the presence of different osaxen, runtime issues that alter how the Applescript system reads in the scriptability information - could affect how that interpretation plays out.


Context is (apparently) everything, sometimes.

Aug 24, 2014 10:01 PM in response to shamsian

Everyone,


Thank you for your help - I tried all suggestion above and none of them worked. Then I decided to exit outlook and then try compiling the script and for whatever reason that worked. I don't know if that is a requirement for compiling Applescripts that the application you are writing the script for cannot be running at compile time but in this case it looks like that is required. Again as soon as I exited Outlook and hit compile the code compiled and all errors where gone and I was able to run it successfully once I restarted Outlook.


Thank you everyone

Aug 24, 2014 11:03 PM in response to shamsian

Ah. Rebuild your launch services database. run this command in terminal:


/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.fram ework/Support/lsregister -kill -r -domain local -domain system -domain user


I've seen a few cases of app's scriptability not being recognized after a 10.9.x update; this seemed to fix them.

Applescript compile fails with "Expected end of line, etc. but found identifier"

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.