Tuesday, September 29, 2020

#1 2010-02-04 11:17:37 am

FreddBowman
Member
Registered: 2010-01-27
Posts: 7

Error -1708: "«script» doesn’t understand the fileList message."

I am somewhat new to Applescript (and Mac scripting/programming in general). I have been stuck on this error for quite some time now. Basically, I have two functions handling almost everything - fileList() and folderList(). I want to call these functions each 4 times, once with each of four destination folders which are passed in as parameters.
The problem is that it won't seem to call each function more than once without erroring out (-1708). Each function call works only if there has been no call before it. Otherwise it will fail. What is the point of functions if you cannot call them more than once (and with different parameters)?

Applescript:



main()

on main()
   set pathToPersonal to ("Macintosh HD:") & "PERSONAL"
   set pathToTaxData to ("Macintosh HD:") & "TaxData"
   set pathToQuickLocal to ("Macintosh HD:") & "QUICKLOCAL"
   set pathToInvDocuments to ("Macintosh HD:") & "INV DOCUMENTS"
   set destNamePersonal to "PERSONAL"
   set destNameTaxData to "TaxData"
   set destNameQuickLocal to "QUICKLOCAL"
   set destNameInvDocuments to "INV DOCUMENTS"
       
   mountVolume()
   makeNewFolder()

   fileList(pathToPersonal, destNamePersonal)
   folderList(pathToPersonal, destNamePersonal)
   
   fileList(pathToTaxData, destNameTaxData)
   folderList(pathToTaxData, destNameTaxData)
   
   fileList(pathToQuickLocal, destNameQuickLocal)
   folderList(pathToQuickLocal, destNameQuickLocal)
   
   fileList(pathToInvDocuments, destNameInvDocuments)
   folderList(pathToInvDocuments, destNameInvDocuments)
   
end main

on mountVolume()
   tell application "Finder"
       mount volume "smb://server/D"
   end tell
end mountVolume

on makeNewFolder()
   tell application "Finder"
       set newFolderName to date string of (current date)
       try
           make new folder at alias ":Volumes:Server:Backup on Server:Incremental Backups" with properties {name:newFolderName}
       on error
           display dialog "There is already a folder with today's date. Please backup this folder, or choose 'Continue Anyway' to overwrite." buttons {"Cancel", "Continue Anyway"}
       end try
   end tell
   
end makeNewFolder

on fileList(pathTo, nameOf)
   
   set newFolderName to date string of (current date) as text
   set sourcePath to pathTo
   set halfdestPath to ":Volumes:Server:Backup on Server:Incremental Backups:" & newFolderName as alias
   
   tell application "Finder"
       set the fileList to (files of alias sourcePath) as alias list
       set modDestDate to ((":Volumes:Server:Backup on Server:Incremental Backups:") & my checkDate()) as alias
       set destPath to make new folder at halfdestPath with properties {name:nameOf}
       repeat with currentFile in fileList
           if modification date of file currentFile > modification date of modDestDate then
               duplicate currentFile to destPath with replacing
           end if
       end repeat
   end tell
   
end fileList

on folderList(pathTo, nameOf)
   
   set newFolderName to date string of (current date) as text
   set sourcePath to pathTo
   --set halfdestPath to ":Volumes:Server:Backup on Server:Incremental Backups:" & newFolderName as alias
   --set destPath to ((halfdestPath as text) & nameOf)
   
   tell application "Finder"
       set the folderList to (folders of alias sourcePath) as alias list
       set modDestDate to ((":Volumes:Server:Backup on Server:Incremental Backups:") & my checkDate()) as alias
       set halfdestPath to ":Volumes:Server:Backup on Server:Incremental Backups:" & newFolderName as alias
       set destPath to ((halfdestPath as text) & nameOf as text) as text
       --display dialog destPath as text
       
       repeat with currentFolder in folderList
           if modification date of folder currentFolder > modification date of modDestDate then
               set fileList to (files of folder currentFolder) as alias list
               set the deepfolderList to (folders of folder currentFolder) as alias list
               set nameFolder to name of currentFolder
               set makeNewFolder to make new folder at destPath with properties {name:nameFolder}
               
               repeat with currentFile in fileList
                   if modification date of file currentFile > modification date of modDestDate then
                       duplicate currentFile to makeNewFolder with replacing
                   end if
               end repeat
               
               repeat with deepcurrentFolder in deepfolderList
                   if modification date of folder deepcurrentFolder > modification date of modDestDate then
                       set deepnameFolder to name of folder deepcurrentFolder
                       set deepnewFolderDest to (destPath) & ":" & (name of currentFolder as text)
                       set makedeepNewFolder to make new folder at (deepnewFolderDest as text) with properties {name:deepnameFolder}
                       set deepfileList to (files of folder deepcurrentFolder) as alias list
                       
                       repeat with deepcurrentFile in deepfileList
                           if modification date of file deepcurrentFile > modification date of modDestDate then
                               duplicate deepcurrentFile to makedeepNewFolder with replacing
                           end if
                       end repeat
                       
                   end if
               end repeat
               
           end if
       end repeat
   end tell
   
end folderList

on checkDate()
   tell application "Finder"
       set theCheckDateItems to every folder of alias ":Volumes:Server:Backup on Server:Incremental Backups"
       set theCheckDateItems to (sort theCheckDateItems by modification date)
       set theCheckDateNames to {}
       set theCheckDateBack to the reverse of theCheckDateItems
       repeat with oneCheckDateFile in theCheckDateBack
           set beginning of theCheckDateNames to name of oneCheckDateFile
       end repeat
   end tell
   set comparisonDate to second item of theCheckDateNames
   return comparisonDate
end checkDate

Last edited by FreddBowman (2010-02-04 02:47:49 pm)

Offline

 

#2 2010-02-04 12:37:52 pm

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11697
Website

Re: Error -1708: "«script» doesn’t understand the fileList message."

Hi,

I don't know, if this causes the error, but there are some syntax problems in the script.
First of all, HFS paths start always with a disk name, not with ":" or "volumes".

I recommend to use a property at the beginning

Applescript:


property backupFolder : "Server:Backup on Server:Incremental Backups:"

and to replace all literal strings with the property name.

This is no syntax problem, but the main() handler is actually not needed.
If the code starts on the top level a run handler is implied.

in the repeat with currentFile in fileList and repeat with deepcurrentFile in deepfileList loops you compare modification dates,
the items of fileList are aliases, so you must omit the keyword file before (deep)currentFile


regards

Stefan

Offline

 

#3 2010-02-04 01:07:50 pm

FreddBowman
Member
Registered: 2010-01-27
Posts: 7

Re: Error -1708: "«script» doesn’t understand the fileList message."

Stefan, thanks for your prompt reply!
I could not get the HFS path to work unless it included both ":" and "Volumes" (e.g. :Volumes:Server:etc). I just double-checked and confirmed this.

I switched over to using "property : etc", removed the incorrect "file" usage in my repeat segments, and removed my main function (c++ is deeply ingrained in my head).

However, I still get the same error message. The thing that baffles me is that each function call works all by itself, but when I try to call a function twice in a row (with different parameters) it errors out.


Filed under: applescript, Error, function, 1708

Offline

 

#4 2010-02-04 06:23:57 pm

chrys
Member
From:: McKinney, TX, USA
Registered: 2007-06-26
Posts: 442

Re: Error -1708: "«script» doesn’t understand the fileList message."

FreddBowman wrote:

The problem is that it won't seem to call each function more than once without erroring out (-1708). Each function call works only if there has been no call before it. Otherwise it will fail. What is the point of functions if you cannot call them more than once (and with different parameters)?

Applescript:

on fileList(pathTo, nameOf)
   -- …
   tell application "Finder"
       set the fileList to (files of alias sourcePath) as alias list
       -- …
   end tell
end fileList

on folderList(pathTo, nameOf)
   -- …
   tell application "Finder"
       set the folderList to (folders of alias sourcePath) as alias list
       -- …
   end tell
end folderList


In AppleScript global variables, properties, and handlers all share the same “name space”. Normally, using a variable in a handler will automatically create that variable as a local variable, but if it has already been declared as a global or a property (or a handler!), it will use the global variable instead.

Handlers are almost “first class” values in AppleScript. It is possible to assign a handler to another global/property to make an alias. And it is possible to overwrite variables that hold handlers with non-handler values, which is what your script is doing.

If you ran your code a third time without recompiling (even the implicit compilation that happens if you try to run after making any kind of edit) you would find that even the first call to the overwritten handler would fail (because of global/property persistence).

Here is a demonstration:

Applescript:

to doStuff(s)
   local doStuff
   set doStuff to s
   doStuff
end doStuff

to doRecursiveStuff(s)
   local doRecursiveStuff
   set doRecursiveStuff to s
   tell doRecursiveStuff to if length is greater than or equal to 4 then return it
   if length of doRecursiveStuff is 0 then set doRecursiveStuff to "r"
   doRecursiveStuff(doRecursiveStuff & doRecursiveStuff) -- this always means the global doRecursiveStuff, even if we have a local doRecursiveStuff
end doRecursiveStuff

to doBadStuff(s)
   set doBadStuff to s
   return doBadStuff
end doBadStuff

on run
   set a to doStuff("1")
   set b to doStuff("2")
   set c to doRecursiveStuff("3")
   set d to doRecursiveStuff("4")
   set e to "5 was not run!"
   set f to "6 was not run!"
   try
       set e to doBadStuff("5")
       try
           set f to doBadStuff("6")
       on error m number n
           set f to {"ERROR in 6", n, m}
       end try
   on error m number n
       set e to {"ERROR in 5", n, m}
   end try
   {a, b, c, d, e, f}
   (*
    * first time gives:
    *    {"1", "2", "3333", "4444", "5", {"ERROR in 6", -1708, "«script» doesn't understand the doBadStuff message."}}
    * second time (without (even implicit) recompilation) gives:
    *    {"1", "2", "3333", "4444", {"ERROR in 5", -1708, "«script» doesn't understand the doBadStuff message."}, "6 was not run!"}
    *)

end run

So, you have a couple of options: change the name of the variables in your handlers, or explicitly declare the variables as local so that they do no overwrite the global variables.

Model: iBook G4 933
AppleScript: 1.10.7
Browser: Safari 4.0.4 (4531.21.10, r54122)
Operating System: Mac OS X (10.4)


--
Chris

Offline

 

#5 2010-02-05 11:22:10 am

FreddBowman
Member
Registered: 2010-01-27
Posts: 7

Re: Error -1708: "«script» doesn’t understand the fileList message."

Chrys, thank you! I changed the name of the variables in the handlers, and it did the trick. I appreciate you not only solving my issue, but taking the time to teach me as well.
   -Fred

Offline

 

#6 2015-01-29 09:32:22 am

mking0310
Member
Registered: 2013-11-12
Posts: 10

Re: Error -1708: "«script» doesn’t understand the fileList message."

Thank you so much for explaining the reason I too got the same error.
I appreciate that you took the time to explain it all.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)