Tuesday, August 4, 2020

#1 2020-07-27 09:17:42 am

kezers
Member
Registered: 2017-01-16
Posts: 7

Applescript to run another Applescript

I would like to run an applescript who pass variables contents to another applescript but it doesn’t work:

Applescript:

set myScript to load script file ((path to desktop folder as text) & "flagsmaker.scpt")
tell myScript
   set its ORDINE to "123456"
   set its RIGA to "01"
   set its COPIE to "001"
   set its TIPO to "Nationals"
end tell

The error I receive is:

error "Can’t make ORDINE into type reference." number -1700 from ORDINE to reference

Anyone can help me? smile

AppleScript: 2.7
Browser: Safari 605.1.15
Operating System: macOS 10.14

Offline

 

#2 2020-07-28 12:13:03 am

peavine
Member
From:: Prescott, Arizona
Registered: 2018-09-04
Posts: 563

Re: Applescript to run another Applescript

kezers wrote:

I would like to run an applescript who pass variables contents to another applescript but it doesn’t work:



I have two suggestions, each of which consists of two scripts. Firstly,

Applescript:

-- first script
set theScript to (path to desktop folder as text) & "Script Two.scpt"

set ORDINE to "123456"
set RIGA to "01"
set COPIE to "001"
set TIPO to "Nationals"

run script file theScript with parameters {ORDINE, RIGA, COPIE, TIPO}

Applescript:

-- second script
on run {ORDINE, RIGA, COPIE, TIPO}
   display dialog ORDINE & space & RIGA & space & COPIE & space & TIPO
end run

Secondly,

Applescript:

-- first script
set myScriptPath to (path to desktop folder as text) & "Script Two.scpt"
set myScript to load script file myScriptPath

tell myScript
   set its ORDINE to "123456"
   set its RIGA to "00001"
   set its COPIE to "001"
   set its TIPO to "Nationals"
end tell

myScript's displayDialog()

Applescript:

-- second script
property ORDINE : missing value
property RIGA : missing value
property COPIE : missing value
property TIPO : missing value

on displayDialog()
   display dialog ORDINE & space & RIGA & space & COPIE & space & TIPO
end displayDialog

Last edited by peavine (2020-07-28 07:19:20 am)


2018 Mac mini - macOS Catalina

Online

 

#3 2020-07-28 03:32:41 am

kezers
Member
Registered: 2017-01-16
Posts: 7

Re: Applescript to run another Applescript

Hey peavine,
Thank you for your answer, the second solution worked perfectly to me!!!

Offline

 

#4 2020-07-28 10:52:52 pm

bmose
Member
From:: Massachusetts
Registered: 2006-01-03
Posts: 335

Re: Applescript to run another Applescript

To add to peavine's two solutions, a third option is to pass values via a handler call. In the following example, the handler called main accepts the passed values:

Applescript:


-- First script
set myScriptPath to (path to desktop folder as text) & "Script Two.scpt"
set myScript to load script file myScriptPath

set ORDINE to "123456"
set RIGA to "01"
set COPIE to "001"
set TIPO to "Nationals"

myScript's main(ORDINE, RIGA, COPIE, TIPO)

-- Second script
on main(ORDINE, RIGA, COPIE, TIPO)
   displayDialog(ORDINE, RIGA, COPIE, TIPO)
end main

on displayDialog(ORDINE, RIGA, COPIE, TIPO)
   display dialog ORDINE & space & RIGA & space & COPIE & space & TIPO
end displayDialog

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)