0

I am still learning Applescript, but I am trying to script some automation for me.

I am trying to get it to create a folder based on user input and then create a sub-folder with contents duplicated from another template folder.

The newly created folders and a file will be renamed based on user input.

Then finally get it to open the newly created file.

However, I am having a problem with it not updating the alias so when I try to open the file it is pointing to the path before the name change.

set {text returned:artistName} to display dialog "Name of Band/Artist?" default answer "" buttons {"Cancel", "Continue"} default button "Continue"
set {text returned:songName} to display dialog "Name of Song?" default answer "" buttons {"Cancel", "Continue"} default button "Continue"

-- This is the session template folder that will be duplicated
set newSession to "Macintosh HD:Users:Chris:Documents:Pro Tools:Automation Templates:New Session_48k"


set clientFolder to alias "Macintosh HD:Users:Chris:Desktop" -- For Testing

tell application "Finder"

    -- Create a main folder to store song session folders
    set artistFolder to make new folder at clientFolder with properties {name:artistName}
    -- Duplicate template into new folder
    set songFolder to duplicate newSession to artistFolder as alias

    -- This gets the session file (Is there a better way to do this)
    set sessionFile to every file of songFolder whose name extension is "ptx"
    set PT_file to item 1 of sessionFile as alias

    -- Change the name of the session folder and Pro Tools file
    set name of PT_file to artistName & "_" & songName & "_0.0"
    set name of songFolder to artistName & " - " & songName

    open file PT_file using "Pro Tools"

return PT_file


end tell

This is what is returned

Result:
alias "/Users/Chris/Desktop/Artist/New Session_48k/New Session_48k.ptx"

How do I get it to point to the actual file location?

Actual Location: /Users/Chris/Desktop/Artist/Artist - Song/Artist_Song_0.0.ptx"

It seems like I am having a very similar problem to the question posted here: https://macscripter.net/viewtopic.php?id=47244

However, I don't understand how to apply the solution to my script.

2
  • I'm a bit confused by your use of 'alias' here. Do you mean it in the applescript sense† or in the Finder's Make Alias (Command-L) sense? Should 'songfolder' and 'sessionfile' be "Finder" copies of the original or Finder aliases that point to the original? So if you double-click on sessionfile, will it actually open the original file in 'newsession'? † see Aliases and Files: developer.apple.com/library/archive/documentation/AppleScript/…
    – Mockman
    Mar 5, 2020 at 9:44
  • Aliases are supposed to keep their references even if the item is renamed or moved, but that is no longer true in some versions of macOS. Take a look at my answer to a similar topic.
    – red_menace
    Mar 5, 2020 at 15:27

0

You must log in to answer this question.

Browse other questions tagged .