I’ve written a script to batch print files, selected by the user, from Quark which works ok.
The script prompts the user to select the files they require printing and then prints the files
to a selected folder as .ps files.
I’m just in the process of adding one or two user-friendly options one of which is asking the
user to confirm their selection. Upon the user pressing button ‘No’ I’m trying to repeat the file
selection process however I’ve hit one or two snags.
Here’s the code for the file selection:-
choose file with prompt "choose the file(s) you wish to print to postscript:" of type "XPRJ" with multiple selections allowed without invisibles
set these_files to result
tell application "Finder"
set these_files to (sort these_files by name)
end tell
set filenameList to {}
set AppleScript's text item delimiters to ":"
repeat with i from 1 to (count of these_files)
set xx to item i of these_files as text
set yy to text item -1 of xx
set filenameList to filenameList & yy & return
end repeat
set AppleScript's text item delimiters to ""
display dialog "You've chosen the following files to" & return & "print to postscript:" & return & return & (filenameList as text) & return & return & "Is this correct" buttons {"Cancel", "No", "Yes"} default button {"Yes"}
set retButton to button returned of result
if retButton = "No" then
return
end if
repeat
choose file with prompt "choose the file(s) you wish to print to postscript:" of type "XPRJ" with multiple selections allowed without invisibles
set these_files to result
tell application "Finder"
set these_files to (sort these_files by name)
end tell
set filenameList to {}
set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {":"}
repeat with i in these_files
set filenameList to filenameList & last text item of (i as text) & return
end repeat
set AppleScript's text item delimiters to ASTID
display dialog "You've chosen the following files to" & return & "print to postscript:" & return & return & (filenameList as text) & return & return & "Is this correct?" buttons {"Cancel", "No", "Yes"} default button {"Yes"}
if button returned of result = "Yes" then exit repeat
end repeat
The way to deal with “Start Over” in a script is to make the part to be started over into a handler:
to doSomething()
display dialog "This is the action" buttons {"OK"}
end doSomething
set done to false
repeat while not done
doSomething()
set D to button returned of (display dialog "Are you done?" buttons {"Nope", "Yup"})
if D is "Yup" then
set done to true
else
set done to false
end if
end repeat
Thanks for scripting a more refined way of getting the filename Stefan, I really must
remeber that sort of thing and implement it more, my version looks a little clumsy.
I was going to implement Stefan’s solution however then I found Adam’s response.
(Have just tried implementing Stefan’s solution and it works a treat! Cheers Stefan)
(Think I’ll have a go implementing Adam’s solution now)
Nothing spectacular - Stefan’s approach is what I use when there’s only one place to choose, and mine is what I use if there are several places in the script from which to return to the beginning.
Thanks for the clarification Adam, I can see that now.
When trying originally to get the code to repeat I’d been looking
for some sort of ‘goto’ statement - yep, the dreaded goto statement!