Thursday, January 18, 2018
  • Index
  •  » Automator
  •  » Copying file name(s) to clipboard with automator

#1 2005-11-21 08:47:46 pm

geniussavant
Member
Registered: 2005-11-22
Posts: 1

Copying file name(s) to clipboard with automator

Hi, this is my first post here, so I hope i'm not being redundant (I am also VERY new to applescript)…

I need to copy file name(s) to the clipboard with automator without the path.
I have used the "Get Folder Contents" command, but I get the whole path when its pasted to TextEdit.

I have successfully used this modified applescript from one that I found here previously:

Applescript:

set f to (choose folder)
tell application "Finder" to set e to name of items of f
if e = {} then
   beep
   display dialog "No items found in the folder “" & f & "”." buttons {"Cancel"} default button 1 with icon 0 giving up after 10
else
   set filelist to {}
   repeat with i from 1 to (count e)
       set end of filelist to ("" & e's item i & ", " & return)
   end repeat
   set the clipboard to "" & filelist
   beep 2
end if

But this uses a choose folder command. Ideally I could use this same applescript in line with automator if I knew how to make this receive the folder from the previous step instead of the choose folder command.

any help appreciated

thanks

Daniel


Filed under: Finder

Offline

 

#2 2005-11-21 09:18:50 pm

Bruce Phillips
Administrator
Registered: 2004-07-16
Posts: 2649

Re: Copying file name(s) to clipboard with automator

Moving this to the Automator forum…

Offline

 

#3 2005-11-21 09:35:52 pm

Bruce Phillips
Administrator
Registered: 2004-07-16
Posts: 2649

Re: Copying file name(s) to clipboard with automator

Try something like this:

Applescript:

on run {input}
   set filenameList to {}
   set ASTID to AppleScript's text item delimiters
   set AppleScript's text item delimiters to {", "}
   
   tell application "Finder"
       launch    
       repeat with thisFolder in input
           set filenameList's end to (name of every item of thisFolder) as Unicode text
       end repeat
   end tell
   
   set AppleScript's text item delimiters to {ASCII character 10}
   set the clipboard to filenameList as Unicode text
   set AppleScript's text item delimiters to ASTID
   
   return {input}
end run

This should seperate the filenames with commas. If multiple folders are passed to the script, then each folder's filenames will be on a seperate line (that's where “ASCII character 10” is used).


Filed under: Finder

Offline

 
  • Index
  •  » Automator
  •  » Copying file name(s) to clipboard with automator

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)