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

AppleScriptObjC | setting variable error

Hello,


I'm building an app in AppleScriptObjC and I've encountered an error.

Here's a part of my script

-----------------------


on chooseSourceFolder_(sender)

set sourceFolder to choose folder with prompt "Scegli la cartella sorgente" showing package contents false

end chooseSourceFolder_

on chooseTargetFolder_(sender)

set targetFolder to choose folder with prompt "Scegli la cartella da sincronizzare" showing package contents false

end chooseTargetFolder_



do shell script "rsync -va " & quoted form of posix path of sourceFolder & " " & quoted form of posix path of targetFolder


---------------


In the shell script part of code it returns an error, saying "The variable sourceFolder is not defined.", even if I clicked the button (chooseSourceFolder_) and selected the folder...


Where am I wrong?

Posted on Jul 16, 2014 5:44 AM

Reply
Question marked as Best reply

Posted on Jul 16, 2014 6:28 AM

The variable sourceFolder's scope is local to the method chooseSourceFolder_, it is not visible outside of that method. (the same is true of targetFolder)


I you want to use it you need to declare it outside of the method. At the top of the file below the script declaration do


property sourceFolder : missing value

property targetFolder : missing value

1 reply
Question marked as Best reply

Jul 16, 2014 6:28 AM in response to Matteo_999

The variable sourceFolder's scope is local to the method chooseSourceFolder_, it is not visible outside of that method. (the same is true of targetFolder)


I you want to use it you need to declare it outside of the method. At the top of the file below the script declaration do


property sourceFolder : missing value

property targetFolder : missing value

AppleScriptObjC | setting variable error

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