I am making my first attempt into applescript and think I have bitten off more than I can chew.
The intended purpose of my script is to do the following:
On inserting files to a folder user is promted for Street number of an apartment, the street name of an apartment and finally the unit number of an apartment.
The script has been set to start with a default location where i presently store my apartment pictures according to a set structure
I am seeking to have finder first see if there is a folder corresponding to street name first
if not create one with name equal to street name
then check to see if there is a folder within street name folder called streetnumber & streetname
if not create it if there is move on to
check if there is a folder named street number and street name and unit number
if there is not create it.
lastly put files intially dropped into folder into correctly named as street number & street name and apt number within street number & name within folder of street name
i.e ask input and receive 1 any street unit 4
place 1 any street unit 4 inside folder called 1 any street contained within folder any street.
after much searching I began adopting a script to fit my needs but think i am running into a problem when trying to determine the first sub folder.
running the script causes error “Can’t make {file "Flathound:pictures", "stName"} into type constant.” number -1700 from {file “Flathound:pictures”, “stName”} to constant
below is the code I have worked out so far.
Any suggestions on how to get on the correct path to solving this issue would be greatly appreciated…
set folderpath to "/Volumes/flathound/pictures" as POSIX file
set stNum to text returned of (display dialog "Enter Street Number:" default answer "")
set stName to text returned of (display dialog "Enter Street Name:" default answer "")
set aptNum to text returned of (display dialog "Enter the Apartment Number:" default answer "")
set address to {stNum & stName & aptNum}
set stnamenum to {stNum & stName}
set path_to_stName to (path to folderpath & text of "stName") as string
set path_to_stnamenum to (path to stNum & text of stName) as string
set path_to_address to (path_to_stnamenum & text of aptNum) as string
property new_folders : {"stName", "stNum", "aptNum"}
check_or_make(folderpath, "stname")
set path_to_user_folderpath to folderpath & "stname"
check_or_make(path_to_stnamenum, "stnum")
set path_to_stnamenum to path_to_address & "aptnum"
check_or_make(path_to_address, "aptnum")
set path_to_address to path_to_stnamenum & "aptnum"
tell application "Finder"
if not (exists alias file (path_to_path_to_stnamenum & "aptnum")) then
make new alias file at (path_to_path_to_address as alias) to folder path_to_address
end if
end tell
repeat with a_folder_name in new_folders
check_or_make(path_to_stnamenum, aptNum)
end repeat
to check_or_make(parent_folder, folder_name)
tell application "Finder"
if not (exists folder (parent_folder & folder_name & ":" as string)) then
do shell script "cd " & quoted form of POSIX path of (parent_folder) & "; mkdir " & quoted form of folder_name
end if
end tell
end check_or_make