Thursday, January 19, 2017

#1 2016-12-16 10:39:31 am

Chrismacteam
Member
From: France
Registered: 2010-09-27
Posts: 48
Website

Call SubRoutine in a script from an other one in Xcode

HI
So i made 2 applescript files in Xcode. I want to call a subroutine from script "InformationImage" an two have the value return. This function "nomFichier" is attache to a button in the interface

Applescript:

script InformationImage
on nomFichier_(sender)
set nbDocs to (current application's Routine's initializeNameFile())
display dialog nbDocs
end nomFichier_
end script

Here is the subRoutine in an other script

Applescript:


script Cartouche
on initializeNameFile()
tell application "Adobe Illustrator"
set listDesDocs to name of every document as list
end tell
log listDesDocs
return listDesDocs
end initializeNameFile:
end script

When i run the app, i have this message
"2016-12-16 17:37:45.074 AppelEntreScript[5108:1673740] *** -[InformationImage nomFichier:]: Routine doesn’t understand the “initializeNameFile” message. (error -1708)"

What is wrong  ? Thanks for your help
Regards


Infographiste Freelance Packaging

Offline

 

#2 2016-12-16 01:00:03 pm

Mark FX
Member
From: UK
Registered: 2011-08-12
Posts: 90

Re: Call SubRoutine in a script from an other one in Xcode

The problem is that your calling a method in a Script named "Routine"

Applescript:


set nbDocs to (current application's Routine's initializeNameFile())

But you should be calling the method in the Scipt called "Cartouche"

Applescript:


set nbDocs to (current application's Cartouche's initializeNameFile())

There are also a couple of minor syntax error's, but not serious ones, her's a simple example of what you should be doing.

Applescript:


script ScriptA

property parent : class "NSObject"

on buttonClick:sender
try
set theResult to (current application's ScriptB's specialFunction()) as list
display dialog (theResult as text)
on error
display dialog "Error occured"
end try
end buttonClick:

end script

Applescript:


script ScriptB

property parent : class "NSObject"

on specialFunction()
set theList to {"One", " ", "Two", " ", "Three", " ", "Four"} as list
return theList
end specialFunction

end script

Alternatively you could have an init method in the ScriptB to retain it in a property for other uses, like this.

Applescript:


script ScriptA

property parent : class "NSObject"

property scriptB : missing value

on buttonClick:sender
set my scriptB to current application's ScriptB's alloc()'s init()
try
set theResult to (my scriptB's specialFunction()) as list
display dialog (theResult as text)
on error
display dialog "Error occured"
end try
end buttonClick:

end script

Applescript:


script ScriptB

property parent : class "NSObject"

on init()
continue init()
return me
end init

on specialFunction()
set theList to {"One", " ", "Two", " ", "Three", " ", "Four"} as list
return theList
end specialFunction

end script

Hope this helps

Regards Mark

Last edited by Mark FX (2016-12-16 01:07:07 pm)

Offline

 

#3 2016-12-17 02:59:06 am

Chrismacteam
Member
From: France
Registered: 2010-09-27
Posts: 48
Website

Re: Call SubRoutine in a script from an other one in Xcode

Hi Mark
Thanks a lot, it works fine.
I was not so far.smile
Regards
Christophe


Infographiste Freelance Packaging

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.049 seconds, 10 queries executed ]

RSS (new topics) RSS (active topics)