1 Reply Latest reply: Jul 16, 2014 6:28 AM by Frank Caggiano
Matteo_999 Level 1 Level 1 (0 points)

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?

  • Frank Caggiano Level 7 Level 7 (25,695 points)

    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