onlineautorecambios

Q: How can I copy a list of filenames in finder and set the clipboard to the filenames separated by comma?

Hi guys, I wonder if someone can give me a hand with a script.

I need to be able to paste a list of filenames of picture files as follows:

0001.jpg, 0002.jpg, 0003.jpg, 0004.jpg

At the moment if I select the files in Finder, copy to clipboard and paste them to TextEdit they are like that:

0001.jpg

0002.jpg

0003.jpg

0004.jpg

 

I found a similar script but a bit different and I'm not sure how to change it. Here it is:

 

set extension_list to {"jpg", "JPG", "jpeg", "JPEG"}

 

set cbNames to paragraphs of (the clipboard as text)

set csvNames to {}

 

set tid to AppleScript's text item delimiters

set AppleScript's text item delimiters to "."

 

-- now make a list of names without extensions

repeat with names in cbNames

  if text item 2 of names is in extension_list then

  copy text item 1 of names to the end of csvNames

  end if

end repeat

log csvNames

 

-- now concatenate filenames as comma separated string

set AppleScript's text item delimiters to ","

set theData to csvNames as text

 

set AppleScript's text item delimiters to tid

iMac, OS X El Capitan (10.11.6)

Posted on Aug 24, 2016 2:05 AM

Close

Q: How can I copy a list of filenames in finder and set the clipboard to the filenames separated by comma?

  • All replies
  • Helpful answers

  • by Roger Wilmut1,

    Roger Wilmut1 Roger Wilmut1 Aug 24, 2016 2:38 AM in response to onlineautorecambios
    Level 9 (77,913 points)
    iTunes
    Aug 24, 2016 2:38 AM in response to onlineautorecambios

    There is a simpler way. Open a TextEdit document and paste the list in. Place the cursor at the end of the first item and drag to the beginning of the second.

    one.jpg

    Hit command-c to copy then command-f to bring up Find. Hit command-v (don't click in the Find field first). Click the 'Replace' checkbox, click in the Replace field and enter a comma and a space.

    Screen Shot 2016-08-24 at 10.15.14.jpg

    Click 'All' then 'Done'.

    Screen Shot 2016-08-24 at 10.37.39.jpg

  • by onlineautorecambios,Solvedanswer

    onlineautorecambios onlineautorecambios Aug 24, 2016 2:47 AM in response to Roger Wilmut1
    Level 1 (4 points)
    Mac OS X
    Aug 24, 2016 2:47 AM in response to Roger Wilmut1

    Hi Roger,

    thanks very much for the idea, but I'm trying to avoid the quantity of steps to achieve that. I already managed to do it with a script and this works as on click on the application created from script editor. I placed a shortcut on the dock and everything is quick. I will paste my script. I'm sure that the script can be improved and I'm open for suggestions.

     

    set extension_list to {"jpg", "JPG", "jpeg", "JPEG"}

    set cbNames to paragraphs of (the clipboard as text)

    set csvNames to {}

     

     

    --Make sure we are copying only jpg's

    set tid to AppleScript's text item delimiters

    set AppleScript's text item delimiters to "."

     

     

    -- now make a list of names

    repeat with names in cbNames

      if text item 2 of names is in extension_list then

      copy names as text to the end of csvNames

      end if

    end repeat

    set AppleScript's text item delimiters to ", "

     

     

    set the clipboard to csvNames as string

  • by Roger Wilmut1,

    Roger Wilmut1 Roger Wilmut1 Aug 24, 2016 3:12 AM in response to onlineautorecambios
    Level 9 (77,913 points)
    iTunes
    Aug 24, 2016 3:12 AM in response to onlineautorecambios

    The script works OK as long as the clipboard contains a list of files with an extension. I would suggest adding as the last line

     

    set AppleScript's text item delimiters to tid

     

    to make sure everything is reset to normal.

     

    You could also add an error dialog:

     

    - now make a list of names

     

    repeat with names in cbNames

     

      if text item 2 of names is in extension_list then

     

      copy names as text to the end of csvNames

     

      else

     

      display dialog "No specified file types found"

     

      end if

     

    end repeat

  • by onlineautorecambios,

    onlineautorecambios onlineautorecambios Aug 24, 2016 3:11 AM in response to Roger Wilmut1
    Level 1 (4 points)
    Mac OS X
    Aug 24, 2016 3:11 AM in response to Roger Wilmut1

    I did that. Thank you for your help.

  • by SGIII,

    SGIII SGIII Aug 24, 2016 1:40 PM in response to onlineautorecambios
    Level 6 (10,627 points)
    Mac OS X
    Aug 24, 2016 1:40 PM in response to onlineautorecambios

    I'm open for suggestions

     

    I'd let Finder do more of the work, get the extension, etc.  Just select the items in Finder and click, and the script will put the text on the clipboard for pasting.

     

    Note that it very rarely is necessary to set text item delimiters back to the original. You see that a lot in old scripts, but these days AppleScript takes care of that bit of housekeeping. The delimiter here is used not to split the text as in your script, but to "join" the list into a string.


    Also AppleScript is case insensitive here; you don't need to check for both "jpg" and "JPG".

     

    SG

     

     

    set theNames to {}

    set text item delimiters to ", " -- remove space if not needed

    tell application "Finder"

      repeat with f in (selection as list)

      if f's name extension is in {"jpg", "jpeg"} then ¬

      copy f's name to theNames's end

      end repeat

    end tell

    set the clipboard to theNames as text

    return theNames -- optional, to see results in Script Editor Result panel

  • by Sejbushe,

    Sejbushe Sejbushe Aug 24, 2016 1:41 PM in response to onlineautorecambios
    Level 1 (4 points)
    Aug 24, 2016 1:41 PM in response to onlineautorecambios

    Hello

    im from Macedonia

    today I lost my iphone   and I dont no were is!!??

     

    can help me any one to find or no

    please contact me: ****

    or viber.*****

     

    <Personal Information Edited by Host>

  • by Roger Wilmut1,

    Roger Wilmut1 Roger Wilmut1 Aug 24, 2016 2:02 PM in response to Sejbushe
    Level 9 (77,913 points)
    iTunes
    Aug 24, 2016 2:02 PM in response to Sejbushe

    You have tacked your question onto a thread which has nothing whatever do do with your problem - why would you expect an answer doing that? You should start your own thread in the iPhone forum: but don't post any personal or contact information. No-one is going to email you and posting your address is an invitation to spam (fortunately the Hosts have removed it from this post.)