Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

help pls looking for filename ending in _fin.pdf then copying to another folder

can someone help me with an applescript to look for a filename ending in _fin.pdf then copy it to another folder


thanks

KLESSER

Mac Pro

Posted on Oct 30, 2014 9:48 AM

Reply
137 replies

Jan 7, 2015 4:15 AM in response to Tony T1

hello tony, can you help me out again?


this script is great, although one of the destinations is a postcript printer hot folder, and is producing slightly different results compared to previous printed files which were printed through acrobat using a Postcript printer driver. Do you know if there is a way of implementing a PPD to the script?


thanks


KL

Jan 7, 2015 6:31 AM in response to Kevlesser

Kevlesser wrote:

Do you know if there is a way of implementing a PPD to the script?


Do you mean test for files that have a PPD extension?

If so, just add another elif to the script:


if [ "${i##*_}" = "fin.pdf" ] ; then

if [ ! -d "$DestFolder" ] ; then

mkdir -v "$DestFolder"

fi

cp -n -v "$i" "$DestFolder"

mv "$i" "${i%.*}"_Copied.pdf

elif [ "${i##*_}" = "fin.ppd" ] ; then

if [ ! -d "$DestFolder" ] ; then

mkdir -v "$DestFolder"

fi

cp -n -v "$i" "$DestFolder"

mv "$i" "${i%.*}"_Copied.ppd

Jan 12, 2015 11:42 AM in response to Kevlesser

Kevlesser wrote:


permissions are all ok. this dest is a shared drive, when i drag and drop files to it it performs correctly, when i use script it turns file to _c but does not copy to mount.


Try the copy from Terminal:

Enter cp -v then [space], then drag the file to the Terminal window, then [space], then drag the destination folder to the Terminal window, then [enter]

Apr 15, 2015 12:42 AM in response to Tony T1

hi tony


this is the last script we have been using.


#!/bin/bash

DestFolder=/Volumes/XEROXLASERS

DestFolder2=/Volumes/Micra\ Portrait-1

function walk_tree {

local directory="$1"

local i

for i in "$directory"/*;

do

if [ "$i" = . -o "$i" = .. ]; then

continue

elif [ -d "$i" ]; then

walk_tree "$i"

else

if [ "${i##*_}" = "fin.pdf" ] ; then

if [ ! -d "$DestFolder" ] ; then

mkdir -v "$DestFolder"

fi

cp -n -v "$i" "$DestFolder"

mv "$i" "${i%.*}"_c.pdf

elif [ "${i##*_}" = "finl.pdf" ] ; then

if [ ! -d "$DestFolder" ] ; then

mkdir -v "$DestFolder"

fi

if [ ! -d "$DestFolder2" ] ; then

mkdir -v "$DestFolder2"

fi

cp -n -v "$i" "$DestFolder"

cp -n -v "$i" "$DestFolder2"

mv "$i" "${i%.*}"_c.pdf

rm "$DestFolder2"/.DS_Store

fi

fi

done

}

walk_tree /Volumes/SPLASH/Kevin\ Lesser # No trailing slash!


If i wanted to add another file ending to send to another device, can you tell me where i need to add, it will be a file ending _fini.pdf and will go to destfolder3=/Volumes/SRA3 Business Cards


note: this file name only goes to 1 destination


thanks


KL

Apr 15, 2015 3:38 AM in response to Kevlesser

Kevlesser wrote:


If i wanted to add another file ending to send to another device, can you tell me where i need to add, it will be a file ending _fini.pdf and will go to destfolder3=/Volumes/SRA3 Business Cards


note: this file name only goes to 1 destination


thanks


KL


Just need to define the variable and add another elif:


#!/bin/bash     
    
DestFolder=/Volumes/XEROXLASERS
DestFolder2=/Volumes/Micra\ Portrait-1
Destfolder3=/Volumes/SRA3\ Business\ Cards
    
function walk_tree {     
  local directory="$1"     
  local i     
  for i in "$directory"/*;     
  do     
       if [ "$i" = . -o "$i" = .. ]; then     
            continue   
       elif [ -d "$i" ]; then  
            walk_tree "$i"   
       else     
            if [ "${i##*_}" = "fin.pdf" ] ; then     
                if [ ! -d  "$DestFolder" ] ; then     
                      mkdir -v "$DestFolder"     
                fi     
                cp -n -v "$i" "$DestFolder"     
                mv "$i" "${i%.*}"_c.pdf       
            elif [ "${i##*_}" = "finl.pdf" ] ; then
                if [ ! -d  "$DestFolder" ] ; then     
                      mkdir -v "$DestFolder"     
                fi     
                if [ ! -d  "$DestFolder2" ] ; then     
                      mkdir -v "$DestFolder2"     
                fi          
                cp -n -v "$i" "$DestFolder"   
                cp -n -v "$i" "$DestFolder2"   
                mv "$i" "${i%.*}"_c.pdf
                rm  "$DestFolder2"/.DS_Store
            elif [ "${i##*_}" = "_fini.pdf" ] ; then
                if [ ! -d  "$DestFolder3" ] ; then     
                    mkdir -v "$DestFolder3"   
                fi
                cp -n -v "$i" "$DestFolder3"
            fi 
       fi     
  done     
}     


walk_tree /Volumes/SPLASH/Kevin\ Lesser # No trailing slash!

help pls looking for filename ending in _fin.pdf then copying to another folder

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.