I am trying to write a script that will select a file from a folder based on it’s name and then perform an action with that file.
For example:
My folder contains files with names that end in A1, A2, B1, B2, etc. I want to then say “if the file in the chosen folder ends with B1 then set it as my desktop image.”
I have this that I’ve been playing with but can’t figure out how to extract individual aliases based on their names.
tell application "Finder"
set ImageList to (entire contents of (choose folder) as alias list)
end tell
tell application "Finder"
set ImageList to (entire contents of (choose folder) as alias list) -- I chose a folder of camera pix.
set pNames to {}
repeat with k from 1 to count ImageList -- the pix end in 002x thru 005x
set N to name of item k of ImageList
-- grab the 3s and number the choices with reference to ImageList position
if N contains "3" then set end of pNames to (k as text) & ") " & N
end repeat
set theChosen to choose from list pNames
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to ")"
set tNum to text item 1 of item 1 of theChosen
set AppleScript's text item delimiters to tid
set tFile to item (tNum as integer) of ImageList -- the desktop pic
end tell