You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

apple script

I am trying to make a script that creates a job folder, with subfolders, for working files.


I acheived that with the script below.


tell application "Finder"
	with timeout of 6000 seconds
		set loc to choose folder with prompt "Choose a location" default location "Volumes/Prepress"
		set JobNumber to text returned of (display dialog "Please enter Job Number (5 digits):" default answer "")
		set JobDiscription to text returned of (display dialog "Please enter a Job Discription:" default answer "")
		set newfoldername to JobNumber & "_" & JobDiscription
		set newfo to make new folder at loc with properties {name:newfoldername}
		make new folder at newfo with properties {name:JobNumber & "_Imposition"}
		make new folder at newfo with properties {name:JobNumber & "_Originals"}
		make new folder at newfo with properties {name:JobNumber & "_Output"}
		make new folder at newfo with properties {name:JobNumber & "_PageLayout"}
		make new folder at newfo with properties {name:JobNumber & "_PDF_Digital"}
		make new folder at newfo with properties {name:JobNumber & "_PDF_Indigo"}
		make new folder at newfo with properties {name:JobNumber & "_PDF_Press"}
		make new folder at newfo with properties {name:JobNumber & "_PDF_WideFormat"}
		make new folder at newfo with properties {name:JobNumber & "_Proof"}
		make new folder at newfo with properties {name:JobNumber & "_Support"}
	end timeout
end tell


I wanted to change the script to automatically point to the path in an active Finder window, but I am getting the error: Can’t make current application into type location reference. Below is my modified code. What am I doing wrong? I am not very experienced in AppleScript.


tell application "Finder" to set fItemList to (selection as alias list)
with timeout of 6000 seconds
	if ((count of fItemList) = 0 or (kind of (info for (item 1 of fItemList)) ≠ "folder")) then
		tell application "Finder" to set fItemPath to POSIX path of (target of front window as text)
	else
		set fItemPath to POSIX path of (item 1 of fItemList)
	end if
	set loc to choose folder with prompt "Choose a location" default location fItemPath
	set JobNumber to text returned of (display dialog "Please enter Job Number (5 digits):" default answer "")
	set JobDiscription to text returned of (display dialog "Please enter a Job Discription:" default answer "")
	set newfoldername to JobNumber & "_" & JobDiscription
	set newfo to make new folder at loc with properties {name:newfoldername}
	make new folder at newfo with properties {name:JobNumber & "_Imposition"}
	make new folder at newfo with properties {name:JobNumber & "_Originals"}
	make new folder at newfo with properties {name:JobNumber & "_Output"}
	make new folder at newfo with properties {name:JobNumber & "_PageLayout"}
	make new folder at newfo with properties {name:JobNumber & "_PDF_Digital"}
	make new folder at newfo with properties {name:JobNumber & "_PDF_Indigo"}
	make new folder at newfo with properties {name:JobNumber & "_PDF_Press"}
	make new folder at newfo with properties {name:JobNumber & "_PDF_WideFormat"}
	make new folder at newfo with properties {name:JobNumber & "_Proof"}
	make new folder at newfo with properties {name:JobNumber & "_Support"}
end timeout



Mac Pro (2023)

Posted on Dec 29, 2023 10:42 AM

Reply

Similar questions

5 replies

Dec 29, 2023 12:06 PM in response to joshfromrossville

Here is an alternative AppleScript that ignores your confusion about POSIX path and AppleScripts inherent usage of HFS paths. It uses a list to avoid all of your make new iterations and results in a folder tree that looks like the following when selecting the SVG folder on my Desktop:



Code:


use scripting additions

set folderNames to {"_Imposition", "_Originals", "_Output", "_PageLayout", "_PDF_Digital", "_PDF_Indigo", "_PDF_Press", "_PDF_WideFormat", "_Proof", "_Support"}

with timeout of 6000 seconds
	tell application "Finder"
		
		set fItemList to (selection as alias list)
		
		if fItemList is {} or not (kind of first item of fItemList) is "Folder" then
			set fItemPath to front Finder window's target as alias
		else
			set fItemPath to first item of fItemList
		end if
		set loc to (choose folder with prompt "Choose a location" default location fItemPath)
		repeat -- now verify five digits were entered
			set jobNumber to text returned of (display dialog "Please enter Job Number (5 digits):" default answer "")
			try
				set foo to jobNumber as number
				if jobNumber > 0 and (count of jobNumber) = 5 then exit repeat
			end try
		end repeat
		set jobDescription to text returned of (display dialog "Please enter a Job Description:" default answer "")
		set newfoldername to jobNumber & "_" & jobDescription
		set newfo to make new folder at loc with properties {name:newfoldername}
		repeat with fname in folderNames
			make new folder at newfo with properties {name:jobNumber & fname}
		end repeat
	end tell
end timeout
return


This was just tested on macOS Sonoma 14.2.1.

Jan 2, 2024 7:35 AM in response to Niel

Is that because failing to do so could cause problems down the line? The script worked with the lines to create a new folder outside the Finder tell block. I went ahead and modified the code to have those lines inside the tell block though. Just trying to learn why, for future scripts. I like to learn why things are done. Thanks for your help!

apple script

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.