I have this problem. I need quit running script when user click to Cancel in “choose from list” window. When user click on Cancel the result is false. Here is e example, but quit command does not work. When I change quit to for example display dialog command this command will be execute.
on VyberZakaznika()
set zakaznici to {"Casia", "Kralicek", "Label Design"}
set zakaznik to choose from list zakaznici with prompt "Vyber zákaznÃka"
if (zakaznik as string) is "false" then quit -- here i need quit (stop executting) script
end VyberZakaznika
Can you help me please with this. I try to solve it 3 hours.
Thanks,
Jiri
Model: PowerBook G4 1.76
AppleScript: 1.10.3
Browser: Safari 417.8
Operating System: Mac OS X (10.4)
Just remove the quotes from the term false and it should work fine for you:
set zakaznik to VyberZakaznika()
display dialog zakaznik
on VyberZakaznika()
set zakaznici to {"Casia", "Kralicek", "Label Design"}
set zakaznik to choose from list zakaznici with prompt "Vyber zákaznÃka"
if zakaznik is false then quit -- here i need quit (stop executting) script
return zakaznik
end VyberZakaznika
If you run this from your Script Editor, the script wil quit, and so will the Script Editor. If you save the script and run it from your Script Library, only the script will quit.
Sending a ‘quit’ event to yourself is only relevant in stay-open applets and Studio-based apps, and all it does there is to instruct the app to quit itself after it’s finished handling the current event. (It won’t cause a script to exit immediately as folk sometimes assume.)
If you want to exit immediately, one solution would be to mimic 'display dialog’s approach by throwing a ‘user cancelled’ error:
on VyberZakaznika()
set zakaznici to {"Casia", "Kralicek", "Label Design"}
set zakaznik to choose from list zakaznici with prompt "Vyber zákaznÃka"
if zakaznik is false then error number -128 -- User cancelled error
return zakaznik
end VyberZakaznika