Reputation: 387
I'm trying to set up an applescript that
This is what i have so far but i'm getting the error : "File /Users/*****/Desktop/Temp/_scripts/ wasn’t found"
tell application "Finder"
set newfoldername to text returned of (display dialog "Project name:" default answer "no name")
set loc to container of (path to me) as alias
set newclient to make new folder at loc with properties {name:newfoldername}
set structure to ((POSIX path of loc) & "_scripts/") as alias
duplicate folder structure to loc
end tell
the _scripts folder is located in the same folder as my applescript. Is it is expecting a file rather than a folder?
Upvotes: 1
Views: 79
Reputation: 726
Vadian's Answer has explained why OP's code doesn't work as expected and already has given a working solution.
For someone else who may need an alias for reuse, we may also convert the file path format by explicitly saying "POSIX file" before the path string:
set structure to POSIX file ((POSIX path of loc) & "_scripts/") as alias
(Since the script should copy to newclient
so the last line is also modified,) full code here:
tell application "Finder"
set newfoldername to text returned of (display dialog "Project name:" default answer "no name")
set loc to container of (path to me) as alias
set newclient to make new folder at loc with properties {name:newfoldername}
set structure to POSIX file ((POSIX path of loc) & "_scripts/") as alias
duplicate folder structure to newclient
end tell
P.S. it is also recommended to check the existence of the _scripts/
folder and non-existence of the folder to be created if they are not controllable.
Upvotes: 1
Reputation: 285082
The most significant mistake is that the Finder does not recognize POSIX paths.
If you want to copy the folder "_scripts"
on the same level as the running script to the new created folder simply use the Finder specifier syntax (folder "_scripts" of loc
)
tell application "Finder"
set newfoldername to text returned of (display dialog "Project name:" default answer "no name")
set loc to container of (path to me)
set newclient to make new folder at loc with properties {name:newfoldername}
duplicate folder "_scripts" of loc to newclient
end tell
Upvotes: 1