property theList : {"item1", "item2", "item3", "item4", "item5"}
set chosenItems to choose from list theList default items theList with multiple selections allowed
if chosenItems is false then return
-- do something with chosenItems
hi Stefan
Thank you very much for helping to get me started. Your code works very well. Mine stumbles. I looked at a previous Nigel suggestion for someone else, but mine involves bundle access and runs into problems.
What is wrong with my handling of the selections?
I keep getting reference problems or if I try to define items as something else I get permission error not allowed to access such a file of the resource.
set item1 to path to resource "sk1_theme.lwtp"
set item2 to path to resource "sk2.lwtp"
set item3 to path to resource "sk3.lwtp"
set item4 to path to resource "sk4.lwtp"
set item5 to path to resource "sk5.lwtp"
set theDestinationFolder to (path to preferences folder from user domain)
set theDestinationFolder to ((theDestinationFolder as text) & "L:themes") as alias
property theList : {"sk1", "sk2", "sk3", "sk4", "sk5"}
set chosenItems to choose from list theList with prompt "Hold command (⌘) to select multiple choices" with multiple selections allowed
if chosenItems is false then return
-- do something with chosenItems
if (chosenItems contains "sk1") then
duplicate item1 to theDestinationFolder with replacing
end if
if (chosenItems contains "sk2") then
duplicate item2 to theDestinationFolder with replacing
end if
if (chosenItems contains "sk3") then
duplicate item3 to theDestinationFolder with replacing
end if
if (chosenItems contains "sk4") then
duplicate item4 to theDestinationFolder with replacing
end if
if (chosenItems contains "sk5") then
duplicate item5 to theDestinationFolder with replacing
end if
quit
I decided instead to have none selected by default instead of all, otherwise it may confuse people.
first of all you need a Finder or System Events tell block to duplicate files.
For the reference to the resources folder I’d do it this way
set resourcesFolder to (path to me as text) & "Contents:Resources:"
.
if (chosenItems contains "sk1") then
tell application "Finder" to duplicate file (resourcesFolder & "sk1_theme.lwtp") to theDestinationFolder with replacing
end if
.
Oh, just realised something. The installer does not quit. Must be stuck in a loop. The last part of the results is:
→ error number 0
end tell
tell application “AppleScript Editor”
quit
Run on its own it quits fine. But if I run it from applescript it says it cannot close whilst the script is still running. Is that anything to be concerned about?
I suddenly started to like path to resource a whole lot better, realizing it is the path to resource of current application that is given back. It is a feature not a bug!
Seriously, accessing an application’s resources become suddenly a whole lot easier.
tell application "Finder"
set uIconPath to POSIX path of (path to resource "Finder.icns")
do shell script "qlmanage -p " & uIconPath & " >dev/null 2>&1 &"
end tell