• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: sub-routines' error
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sub-routines' error


  • Subject: Re: sub-routines' error
  • From: "Stockly, Ed" <email@hidden>
  • Date: Wed, 10 May 2017 17:42:34 +0000
  • Thread-topic: sub-routines' error

Maik, here is a working version your script with a minimal amount of changes to make it work. 


First, your handler (sub-routine) was not explicitly returning a value, as the version below does, but your run handler was accessing the last appleScript result, which is global. So it seemed as if there was a return value.


Second, as others pointed out your variable name was the same as your handler name which confuses appleScript.


HTH,


Ed






use AppleScript version "2.4" -- Yosemite (10.10) or later

use scripting additions


on run

set the_List to {}

activate

set the_Files to (choose file with prompt "Please select a file to process:" with multiple selections allowed)

repeat with f from 1 to (count of the_Files)

set the_File to (the_Files's item f)

set the_List's end to the_File

end repeat

display dialog ("the_Files: " & the_Files & "


the_List: " & the_List)

end run


on the_Name(the_File)

tell application "Finder"

set fileName to name of the_File

end tell

return fileName

end the_Name



 


From: AppleScript-Users <applescript-users-bounces+ed.stockly=email@hidden> on behalf of Maik Waschfeld <email@hidden>
Date: Wednesday, May 10, 2017 at 4:59 AM
To: AppleScript Digest <email@hidden>
Subject: sub-routines' error

Hi AS-users,

I’m trying to get a little deeper into the sub-routine-thing.
But I’m stuck at a strange error -1708, that I can reproduce with the following script.

useAppleScriptversion "2.4" -- Yosemite (10.10) or later
usescripting additions

onrun
setthe_Listto {}


activate


setthe_Filesto (choose filewith prompt "Please select a file to process:" with multiple selections allowed)


repeatwith ffrom 1 to (countof the_Files)
setthe_Fileto (the_Files'sitemf)


mythe_Name(the_File)


setthe_List'send to (the_Name)
endrepeat


display dialog ("the_Files: " & the_Files & "\n\nthe_List: " & the_List)


endrun

onthe_Name(the_File)
tellapplication "Finder"
setthe_Nameto nameof the_File
endtell
endthe_Name


When selecting more than one file, so that the sub-routine runs multiple times, I get this error:
error „«script» doesn’t understand the message „the_Name“.“ number -1708 from «script»

As far as I understand AppleScript, there’s basically nothing wrong with the script.

If I replace the „my the_Name(the_File)“ line with
tell application "Finder"
set the_Name to name of the_File
end tell
no error comes up, even when I select quite a lot files.

Any hints, how I get it to work, anyway?


With kindest regards…
…Maik Waschfeld

(sent from my MBAir11)


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >sub-routines' error (From: Maik Waschfeld <email@hidden>)

  • Prev by Date: Re: sub-routines' error
  • Next by Date: Re: Inserting a Custom Header in BBEdit
  • Previous by thread: Re: sub-routines' error
  • Next by thread: Inserting a Custom Header in BBEdit
  • Index(es):
    • Date
    • Thread