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
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
Lacking a little in details there.
Do you want to find every file on disk? in a specific folder?
Is there one file? many?
Where do you want to copy to? To a specific folder? to somewhere relative to where the source file was?
In general what you want is trivial, but the devil is in the details.
From your post, this will do what you ask, but it may not be enough depending on the missing answers to the questions.
tell application "Finder"
set srcFolder to (choose folder with prompt "Select the source folder")
set dstFolder to (choose folder with prompt "Where do you want to move the files to?")
set FilesToMove to every file of srcFolder whose name ends with "_fin.pdf"
moveFilesToMovetodstFolder
end tell
You can change srcFolder and dstFolder to be any other reference you like - in this case it prompts you to select the respective folders, but you could also hard-code a specific path here (... folder "blah" of disk "foo", ... folder "Bar" of (path to desktop), etc.)
Another way is to wrap the unix find command in an Applescript do shell script command:
do shell script "find ~ -iname '*_fin.pdf' -exec cp {} ~/Desktop \\;"
Note: searches the Home Directory ( ~ ) and copies to the Desktop (use / to search the drive)
_fin will sit in various sub folders of a specific folder on an smb mounted Nas. They should copy to only one other folder on same nas. Then maybe the original could be colour labelled once it has been copied. I would want to automate this whole process often say every 30 seconds? Colour labelling so not to repeat the copy process.
Kevlesser wrote:
_fin will sit in various sub folders of a specific folder on an smb mounted Nas. They should copy to only one other folder on same nas. Then maybe the original could be colour labelled once it has been copied. I would want to automate this whole process often say every 30 seconds? Colour labelling so not to repeat the copy process.
Instead of Applescript, consider using launchd to trigger the find and copy every 30 seconds. You can use the cp -n flag to skip an existing file (so no need to label the file).
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.tony.cpFiles</string>
<key>ProgramArguments</key>
<array>
<string>find</string>
<string>/NASDir</string>
<string>-iname</string>
<string>*_fin.pdf</string>
<string>-exec</string>
<string>cp</string>
<string>-n</string>
<string>{}</string>
<string>/NASDir/DestFolder</string>
<string>\;</string>
</array>
<key>StartInterval</key>
<integer>30</integer>
</dict>
</plist>
Change /NASDir and /NASDir/DestFolder to the appropriate folders and then save the above as a .plist file and place in ~/Library/LaunchAgents to run when you log in, or in /Library/LaunchAgents to run when anyone logs in or in /Library/LaunchDaemons to run at system start up. (You'll need to log-out and back in the first time to take effect)
If you need to preserve file attributes, take a look at the cp options (man cp)
tony, i am not a programmer and this is way above my head!!!
Kevlesser wrote:
tony, i am not a programmer and this is way above my head!!!
All you needed to do was copy the file I posted (as "whatever.plist") to ~/Library/LaunchAgents,
then log out and back in (or re-boot).
This is the preferred way of doing what you asked for (i.e. running a command every 30 seconds)
To learn about launchd see: Creating Launch Daemons and Agents
tony, copy it how?, when i copy into textedit it does not allow a .plist suffix
also copy to system library or home library?
Kevlesser wrote:
tony, copy it how?, when i copy into textedit it does not allow a .plist suffix
You need to copy into a plain text file (TextEdit->Format->Make Plain Text), then you can use the .plist ext.
Kevlesser wrote:
also copy to system library or home library?
If you're the only user, or only want it to run when you're logged in, then copy to the ~/Library/LaunchAgents Folder
sure,done all that but not seem to be copying, thankyou for your patience, does my directory look correct in previous screenshot.?
I'm not sure why (maybe someone can assist), but I cannot get the launchd to run as I posted,
however, if I put the find in a script, and have launchd run the script, it will work,
So….
1. Save this as a plain text file (i.e. NAScopy.sh), then in terminal, make it executable with the command: chmod u+x ~/Desktop/NAScopy.sh
#!/bin/bash
/usr/bin/find /NASDir -iname *_fin.pdf -exec cp -n {} /NASDir/DestFolder \;
Change /NASDir and /NASDir/DestFolder to the appropriate folders
2. Use this .plist in place of the previous one:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.tony.cpFiles</string>
<key>ProgramArguments</key>
<array>
<string>/Users/Tony/Desktop/NAScopy.sh</string>
</array>
<key>StartInterval</key>
<integer>30</integer>
</dict>
</plist>
Change /Users/Tony/Desktop/ to the Folder where you place the NAScopy.sh file
Sorry this got more complicated, but this worked when I tested.
I'm not sure why (maybe someone can assist)
Add EnableGlobbing to the plist.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"
<plist version="1.0">
<dict>
<key>EnableGlobbing</key>
<true/>
I'll suggest that you add the absolute path to any commands.
<key>ProgramArguments</key>
<array>
<string>/usr/bin/find</string>
Your original Launch Agent works as prescribed.
@KLESSER
The plist name needs to be the same name as the Label with the .plist suffix.
com.tony.cpFiles.plist
You may need to logout then login for the Launch Agent to run.
help pls looking for filename ending in _fin.pdf then copying to another folder