• 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: Christopher Stone <email@hidden>
  • Date: Wed, 10 May 2017 09:18:01 -0500

On 05/10/2017, at 06:59, Maik Waschfeld <email@hidden> wrote:
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.


Hey Maik,

Axel has explained the problem nicely, so I'll just rewrite your script more or less the way I would write it.

Display Dialog is a painful mechanism for displaying a result, unless you need to be interactive with the script — so I'm going to use TextEdit instead.

I'm using the shell to send the text to TextEdit, because this specific method will automatically create a temp file I don't need to manage.

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

set screenBounds to desktopBounds()
set item 2 of screenBounds to 23
set fileNameList to {}

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

repeat with theFile in fileList
    set end of fileNameList to getFileName(theFile) of me
end repeat

set AppleScript's text item delimiters to linefeed

set stdOUT to ("HFS Path List: " & linefeed & linefeed & (fileList as text) & linefeed & linefeed & "File Name List:" & linefeed & linefeed & fileNameList)

# Send text from the variable stdOUT to the shell's default text editor (TextEdit unless altered) as a temp file.
set shCMD to "echo " & quoted form of stdOUT & " | open -f"
do shell script shCMD

tell application "TextEdit"
    activate
    set bounds of front window to screenBounds
end tell

------------------------------------------------------------------------------
--» HANDLERS
------------------------------------------------------------------------------
on desktopBounds()
    tell application "Finder"
        return bounds of window of desktop
    end tell
end desktopBounds
------------------------------------------------------------------------------
on getFileName(theFile)
    tell application "Finder"
        return the name of theFile
    end tell
end getFileName
------------------------------------------------------------------------------

For experiments of this sort I'd use the Finder selection (as alias) instead of a choose file dialog, because they both produce a list of aliases and because the former doesn't delay me like the latter does.

------------------------------------------------------------------------------
tell application "Finder"
set finderSelectionList to selection as alias list
if length of finderSelectionList = 0 then error "No files were selected in the Finder!"
end tell
------------------------------------------------------------------------------

--
Best Regards,
Chris

 _______________________________________________
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: Inserting a Custom Header in BBEdit
  • Previous by thread: Re: sub-routines' error
  • Next by thread: Re: sub-routines' error
  • Index(es):
    • Date
    • Thread