Monday, December 11, 2017

#1 2017-09-10 01:22:13 pm

iGods
Member
Registered: 2010-04-01
Posts: 13

OS X Sierra Applescript libraries: The variable xxxx is not defined

I've recently upgraded from OS X 10.9.5 to OS 10.12.6. When I did, my complex Applescripts broke. Specifically, my scripts can no longer see their libraries.

For example, one of the library files that I use is in a file called: server properties.scpt

In that script file, I have defined:

-------------------------------
script serverPropertiesLibrary
   
    -- server properties
    property odbcUser : "bob"

--- <snip>

end script
-------------------------------

I access that library in this example call:

repeat with loopProjectSet in ProjectSets
    updateReport(loopProjectSet, serverPropertiesLibrary's AffiliateSets, serverPropertiesLibrary's odbcUser, serverPropertiesLibrary's odbcPass, serverPropertiesLibrary's extranetusername, serverPropertiesLibrary's extranetpassword)
end repeat


When I run my scripts, either as applications from the Finder, or inside Script Editor or Script Debugger, I get the error (pointing to the first instance of serverPropertiesLibrary's):

Applescript Error:
The variable serverPropertiesLibrary is not defined.

I Googled the issue the best I could, and did read up on setting the environment variable to point to the /opt/local/Script Libraries and /usr/local/Script Libraries . I added that env variable to my bash profile, and I can see the ENV variable set after my reboot (just to be sure):

dev:~ cameron$ env
... snip
OSA_LIBRARY_PATH=/opt/local/Script Libraries:/usr/local/Script Libraries

... and I confirmed that the scripts are in place:

dev:~ cameron$ ls -alG "/opt/local/Script Libraries"
total 8376
drwxr-xr-x  10 cameron  wheel      340  7 Sep 21:43 .
drwxr-xr-x  16 cameron  wheel      544  7 Sep 21:43 ..
-rw-r--r--@  1 cameron  wheel     6148  7 Sep 21:43 .DS_Store
-rw-r--r--@  1 cameron  wheel  1825928  5 Apr  2015 Script Library Aliases
-rw-r--r--@  1 cameron  wheel     5510 21 Apr  2016 server properties.scpt
-rw-r--r--@  1 cameron  wheel    92514  6 Apr  2015 subroutines-excel.scpt
-rw-r--r--@  1 cameron  wheel    32562 15 Aug  2014 subroutines-mail.scpt
-rw-r--r--@  1 cameron  wheel    19420 23 Jul  2013 subroutines-progressbar.scpt
-rw-r--r--@  1 cameron  wheel   121624  4 Jan  2015 subroutines-status report cloner.scpt
-rw-r--r--@  1 cameron  wheel    92360  6 Apr  2015 subroutines.scpt


Still, my script won't run, same error. Is that bash env variable just not accessible to my logged in GUI user account? Do I need to migrate all my libraries into the script's bundle (completely defeating the purpose of libraries)?


Sorry to bother the group is this has been covered in the past, I just can't wrap my head around this silly issue.

Thank you for your help.

Offline

 

#2 2017-09-10 06:43:17 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5197

Re: OS X Sierra Applescript libraries: The variable xxxx is not defined

iGods wrote:

Do I need to migrate all my libraries into the script's bundle (completely defeating the purpose of libraries)?



No, but it's not clear whether you are calling them correctly -- you're certainly putting them in an atypical directory.

Are you including "use script" statements? If not, setting OSA_LIBRARY_PATH will do nothing.

The way to use a library is:

* Store it in the library search path. ~/Libraries/Script Libraries is the typical place.

* Include a "use script statement", such as:

Applescript:

use myLib : script "server properties"
use scripting additions -- if you also intend to use scripting addition commands

set x to myLib's someHandler()

It might be easiest to start by reading the section on Script Libraries in the AppleScript Language Guide:
https://developer.apple.com/library/con … tLangGuide


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#3 2017-09-11 11:21:02 am

iGods
Member
Registered: 2010-04-01
Posts: 13

Re: OS X Sierra Applescript libraries: The variable xxxx is not defined

huge thanks for the help! I mean huge! actually, I've been scripting for over 20 years, it's just that Apple screwed everything with their upgrades. I used to manage my libraries in Script Debugger; it was SD that moved my libraries there in the first place. I also read up that those 2 locations are quite common for libs as well. but, your suggestion worked, so I'll stick with you!

Last edited by iGods (2017-09-11 12:13:41 pm)

Offline

 

#4 2017-09-11 03:25:21 pm

iGods
Member
Registered: 2010-04-01
Posts: 13

Re: OS X Sierra Applescript libraries: The variable xxxx is not defined

I didn't get that far. I can compile the script without complaint, but now it won't run:

// main script:
use serverPropertiesLibrary : script "server properties.scpt"
use scripting additions

updateReport(loopProjectSet, serverPropertiesLibrary's AffiliateSets, serverPropertiesLibrary's odbcUser, serverPropertiesLibrary's odbcPass, serverPropertiesLibrary's extranetusername, serverPropertiesLibrary's extranetpassword)



// server properties.scpt:

script serverPropertiesLibrary

    property AffiliateSets : {¬
        {"igods", "http", "extranet.igods.com", "stats.igods.com", "project", "iGods", null} ¬
            }

end script



// result:
AppleScript Execution Error
Can’t make AffiliateSets into type reference.

Offline

 

#5 2017-09-11 06:52:05 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5197

Re: OS X Sierra Applescript libraries: The variable xxxx is not defined

iGods wrote:

// server properties.scpt:

script serverPropertiesLibrary

    property AffiliateSets : {¬
        {"igods", "http", "extranet.igods.com", "stats.igods.com", "project", "iGods", null} ¬
            }

end script



You don't need to make it a script object. Change it to simply:

Applescript:

property AffiliateSets : {¬
   {"igods", "http", "extranet.igods.com", "stats.igods.com", "project", "iGods", null} ¬
       }

(Please wrap your code in AppleScript tags using the button at the top of the message view.)


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#6 2017-09-12 12:33:49 pm

iGods
Member
Registered: 2010-04-01
Posts: 13

Re: OS X Sierra Applescript libraries: The variable xxxx is not defined

I can't get this to work.

now I can't access functions in my library files, e.g.:

-- main script:

Applescript:


use script "subroutines.scpt"
-- snip
set targetProjectNameEncoded to my replace_chars(targetProjectName, " ", "%20")

-- library script:

Applescript:


on replace_chars(txt, srch, repl)
   copy AppleScript's text item delimiters to theDelims
   set AppleScript's text item delimiters to the srch
   set the item_list to every text item of txt
   set AppleScript's text item delimiters to the repl
   set txt to the item_list as string
   set AppleScript's text item delimiters to theDelims
   return txt
end replace_chars

-- result:
«script» doesn’t understand the “replace_chars” message.


"load script file" no longer seems to be the way to load scripts, either, I can't even compile using that command (even though the documentation seems to focus on that method).

I've tried reading up on AppleScript libraries, but there doesn't seem to be much about them, certainly nothing about the "use" command... it all points to "load script" which doesn't work for me.

I knew I was going to be in trouble when I upgraded my OS, but this is beyond tedious.

Last edited by iGods (2017-09-12 12:36:05 pm)

Offline

 

#7 2017-09-12 01:47:35 pm

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 4449

Re: OS X Sierra Applescript libraries: The variable xxxx is not defined

iGods wrote:

I can't get this to work.

now I can't access functions in my library files, e.g.:

-- main script:

Applescript:


use script "subroutines.scpt"
-- snip
set targetProjectNameEncoded to my replace_chars(targetProjectName, " ", "%20")


Hi.

Applescript:

use subroutines : script "subroutines.scpt" -- The word after 'use' is a variable. You can call it whatever you like.

set targetProjecNameEncoded to subroutines's replace_chars(targetProjectName, " ", "%20")


NG

Offline

 

#8 2017-09-12 02:16:58 pm

iGods
Member
Registered: 2010-04-01
Posts: 13

Re: OS X Sierra Applescript libraries: The variable xxxx is not defined

ugh! I am going to have to rewrite ********so********** much code. and I have 6 libraries that I use, so I'll have to figure out which library to reference in place of "my".

I completely regret upgrading my operating system. Script Debugger used to make this so easy. Is there even a way to analyze a script to ensure its library dependencies are intact? Or do I have to run absolutely every possible code branch to test it?

this is a nightmare. thank you all so much for your help in getting here, I couldn't manage AppleScript without your support.

Last edited by iGods (2017-09-12 03:55:23 pm)

Offline

 

#9 2017-09-12 06:28:40 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5197

Re: OS X Sierra Applescript libraries: The variable xxxx is not defined

If you open your old scripts with Script Debugger 6, it will offer to migrate them. It won't do everything for you, but it will save you a lot of work.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)