0

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

3
  • 3
    Please don't delete questions which have been put on hold. Adress the close reason instead with an edit.
    – nohillside
    Commented Sep 17, 2021 at 15:30
  • 2
    Also, where on this site (link) did you find this?
    – nohillside
    Commented Sep 17, 2021 at 15:30
  • 1
    PaulDaniels, Welcome to Ask Different. -- Had you actually included this code in your other, now deleted, question it would have been so much easier! Please take the time to read How do I ask a good question? and if you want help debugging code when it errors, then also read How to create a Minimal, Reproducible Example and conform your queries to it. Thanks. Commented Sep 17, 2021 at 15:39

1 Answer 1

3

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.

1
  • 2
    @PaulDaniels If you are satisfied with the answer you can press the tick (✔️) below the voting arrows. It lets the community and outsiders know that’s the correct answer and serves as a guide for the future. It also increases your reputation in the community.
    – sfxedit
    Commented Sep 17, 2021 at 16:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .