Running a script to create a file hierarchy.

Okay so this script works:


property prefix : ""

set folderpath to choose folder with prompt "Choose Destination Folder"
repeat
	set prefix to text returned of (display dialog "Enter Prefix:" default answer "")
	tell application "System Events" to exists folder prefix of folderpath
	exit repeat
	
end repeat

set folderHierarchy to "/{" & folderName("Projects") & ¬
	"," & folderName("Raws") & ¬
	"," & folderName("Final Exports") & "}"
do shell script "/bin/mkdir -p " & quoted form of POSIX path of folderpath & "/" & quoted form of prefix & "/" & folderHierarchy

on folderName(v)
	return quoted form of (v)
end folderName

I tried to set a dafault path instead of the user having to select the path. This is what I did:


property prefix : ""

set folderpath to POSIX path of ("/Volumes/HPT-RAID5")
repeat
	set prefix to text returned of (display dialog "Enter Prefix:" default answer "")
	tell application "System Events" to exists folder prefix of folderpath
	exit repeat
	
end repeat

set folderHierarchy to "/{" & folderName("Projects") & ¬
	"," & folderName("Raws") & ¬
	"," & folderName("Final Exports") & "}"
do shell script "/bin/mkdir -p " & quoted form of POSIX path of folderpath & "/" & quoted form of prefix & "/" & folderHierarchy

on folderName(v)
	return quoted form of (v)
end folderName

And I keep getting this error: “Can’t make “testerrrrrrr” into type integer.”

Where ‘testerrrrrr’ is the name I choose for the “prefix”

Any tips? The original thread I pulled this from suggested this:

But I can’t make much sense of it (beginner here)

Thanks for any help, guys.

Two changes:

  1. The path must be an HFS path (without any Volumes prefix)
set folderpath to "HPT-RAID5:"
  1. Add the keyword folder in the System Events line
tell application "System Events" to exists folder prefix of folder folderpath

Reason for the changes:
choose folder returns an alias specifier, you can get the POSIX path directly from an HFS path but System Events needs an object specifier keyword using this particular syntax.

Your second instruction :

set folderpath to POSIX path of ("/Volumes/HPT-RAID5")

is wrong

Try to replace it by

set folderpath to POSIX file ("/Volumes/HPT-RAID5")
set folderpath to (folderpath as text) as alias

I converted the file object created at first into an alias because without that, the instruction:
tell application “System Events” to exists folder prefix of folderpath
would fail.

Yvan KOENIG running Sierra 10.12.2 in French (VALLAURIS, France) jeudi 12 janvier 2017 18:59:11

Yvan,

to coerce POSIX path to POSIX file and back to POSIX path is not very efficient.

I assumed that the POSIX path was given by an other part of a larger script.

If I was wrong it’s clear that

set folderpath to "HPT-RAID5:" as alias

would be more efficient.

Yvan KOENIG running Sierra 10.12 in french (VALLAURIS, France) jeudi 12 janvier 2017 19:34:40