Tuesday, December 12, 2017

#1 2017-11-29 09:28:59 am

markconwaymunro
Member
Registered: 2017-11-28
Posts: 2

Use command conflicts with Standard Addition calls?

When the use command is placed above a call to standard additions — like choose folder or path to — it causes the script to error when compiling. If the command order is reversed, it works. anyone have insight into why and how to work around this problem?

Example 1

Applescript:

Use myLibrary : script "Hello"
set pathToDesktop to (path to desktop folder)
-- Error: A to:desktop can’t go after this path. (highlighting path to desktop)

set pathToDesktop to (path to desktop folder)
use myLibrary : script "Hello"
-- Successful compile

Example 2

Applescript:

Use myLibrary : script "Hello"
set pathToDesktop to choose folder
-- Error: Expected end of line, etc. but found identifier. (highlighting choose folder)

set pathToDesktop to choose folder
use myLibrary : script "Hello"
-- Successful compile

I am running MacOS High Seirra 10.13.1

Model: MacBook Pro with Touchbar (2016)
AppleScript: 2.7
Browser: Safari 604.3.5
Operating System: Other

Offline

 

#2 2017-11-29 10:09:23 am

DJ Bazzie Wazzie
Member
From:: the Netherlands
Registered: 2004-10-20
Posts: 2727
Website

Re: Use command conflicts with Standard Addition calls?

When the use expression is used in AppleScript the interpreter knows that it is a "new" AppleScript format and the script is interpreted differently. When you use an scripting addition command before the use expression the old format is used. The new applescript format has scripting additions turned off by default while in the old format it is turned on.

The reason it behaves this way is because determination between new and old format is done while parsing long before semantic analyzing.

To answer your question. When using the use expression and want to make use of scripting additions you should use the expression:

Applescript:

use scripting additions

So in your example you should always use:

Applescript:

use myLibrary : script "test"
use scripting additions
set pathToDesktop to (path to desktop folder)

Last edited by DJ Bazzie Wazzie (2017-11-29 10:10:17 am)

Offline

 

#3 2017-11-29 10:17:08 am

markconwaymunro
Member
Registered: 2017-11-28
Posts: 2

Re: Use command conflicts with Standard Addition calls?

Of course. Thank you!

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)