Apple script - set path to a custom path

I found this on this site

tell application "Finder"
    set p to path to desktop -- Or whatever path you want
    make new folder at p with properties {name:"New Folder"}
end tell

I want to use a different path for instance /tmp/newbusiness/

It says "Or whatever path you want" How can I make it what ever path I want?

Thanks


Solution 1:

Example AppleScript code:

tell application "Finder"
    set p to (POSIX file "/tmp/newbusiness" as alias) -- Or whatever path you want
    make new folder at p with properties {name:"New Folder"}
end tell

Notes:

As coded, the target folder must already exist, e.g., "/tmp/newbusiness" otherwise it will error.

path to desktop is a Scripting Additions built-in and returns the path to your Desktop as an alias. Have look at: path to (folder)

If you want to hard code a POSIX path and using it in a tell application "Finder" block, then you need to reference it as POSIX file and in my example I coerced it to an alias as that is what Finder works best with. Have a look at: as (coercion)



Note: The example AppleScript code is just that and sans any included error handling does not contain any additional error handling as may be appropriate. The onus is upon the user to add any error handling as may be appropriate, needed or wanted. Have a look at the try statement and error statement in the AppleScript Language Guide. See also, Working with Errors. Additionally, the use of the delay command may be necessary between events where appropriate, e.g. delay 0.5, with the value of the delay set appropriately.