Possible to get folder name in Automator?

Discussion in 'Mac Programming' started by whitecastle, Jan 25, 2013.

  1. macrumors newbie

    Joined:
    Jan 25, 2013
    #1
    Hi,

    I'm not a programmer but I'm trying to build an Applescript that will take all the files in a folder and create a playlist in iTunes from that folder.

    I can successfully get the action to complete, however, the name of the playlist is set to the path of every file within the folder. So the playlist name is super long, being the full path of every track in the folder back to back.

    Is there a way to capture JUST the folder name and set it as the variable to use when naming my playlist?

    Here's an image of the current workflow: Note the FolderName variable is just a placeholder.

    [​IMG]
     
  2. macrumors 6502

    Joined:
    May 29, 2011
    Location:
    Littleton, Colorado, USA
    #2
    You can use a third party action or a Run AppleScript action to get the name of the folder to put into a variable, for example:

    Code:
    on run {input, parameters}
    	tell application "System Events" to return name of first item of input
    end run
    Note that your application will accept multiple folders and files, so you should probably filter for folders or convert to a Service that just accepts folders.
     
  3. thread starter macrumors newbie

    Joined:
    Jan 25, 2013
    #3
    Thanks for your reply.

    I'll have to figure out the code, but would it read something like this:

    Code:
    on run {input, parameters}
    	tell application "System Events" to return name of first item of input
            [COLOR="Red"][I]filter input to only basefolder (totally made up command)[/I][/COLOR] 
    end run
    And at what point in the workflow would this script go?
     
  4. macrumors 6502

    Joined:
    May 29, 2011
    Location:
    Littleton, Colorado, USA
    #4
    You can use a Filter Finder Items action, for example:

    1. Your application is passed files and folders
    2. Filter Finder Items - Find files where kind is folder
    3. Set Value of Variable (e.g. "input") - save original input folder(s)
    4. Run AppleScript - get name of first folder
    5. Set Value of Variable (e.g. "folder name") - save folder name
    6. Get Value of Variable "input" - set option to Ignore input
    7. Get Folder Contents
    8. Import Files into iTunes - use "folder name" for new playlist
     
  5. garysdavies, Jul 8, 2013
    Last edited: Jul 8, 2013

    macrumors newbie

    Joined:
    Jul 8, 2013
    #5
    MOre help

    Hi Whitecastle,

    I have a similar issue and don't quite follow the script. I am trying to get automator to do the following. I have a folder of pics. I would like to name an album in iPhoto the same as the folder and import the pics.
     
  6. macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #6
    Just follow Red Menace's steps and replace step 8 with :

    8. Import Files into iPhoto - use "folder name" for new album

    I'm not quite sure if that is the correct name of the action.
     

Share This Page