As a relativly new MacScripter I could use some help/pointers with the following action I need to do.
I need to take a bunch of PDF files and put them on an SMB share in a specified folder. Once at that folder, I need to do the following for each file:
-Check to see if there is a folder with the same name as the PDF file (without the extnesion of course)
-If there is, then place the PDF file in the folder of the same name.
-If there is not, then create a folder of the same name as the PDF and place the PDF inside of that newly created folder.
Any help, pointers or suggestions would be greatly appreciated.
Thanks.
Bill Briggs has an excellent tutorial on file/folder organization:
http://maccentral.macworld.com/features/applescriptprimer36/
I’m afraid I don’t know what an SMB share is. (Actually, I looked it up on the Internet… and I still don’t know what it is ).
Here is a solution to your problem, IF your target was a normal folder rather than whatever SMB share is:
-- AppleScript droplet. Drag and drop your pdf files onto this script
-- saved as an application.
property targetFolder : alias "panther108:Pretending to be an SMB share:"
on open (systemItems)
set astids to AppleScript's text item delimiters
try
set targetPath to targetFolder as string
-- Coerce the alias list to path-strings
--
set AppleScript's text item delimiters to "/:"
set systemPaths to (systemItems as string)'s text items
-- The names of the folders of the targetFolder
--
tell application "Finder" to set folderNames to ¬
name of every folder of folder (targetPath)
set AppleScript's text item delimiters to ":"
repeat with i from 1 to systemItems's length
set pathString to systemPaths's item i
if (pathString ends with ".pdf") then -- filter the pdfs from drag/drop
set pathString to pathString's ¬
text from text item -1 to character -5 -- remove ext.
if (folderNames contains pathString) then -- folder exists
-- "duplicate" can be changed to "move":
--
tell application "Finder" to ¬
duplicate file ((systemItems's item i) as string) to ¬
folder (pathString) of folder (targetPath) ¬
with replacing
--
-- with replacing means that if the script is run 2 or
-- more times, and a drag/dropped pdf file has the same
-- name as a previous one, then the one just dropped
-- replaces the existing one.
else -- create the folder
tell application "Finder"
make new (folder) at (folder targetPath) ¬
with properties {name:pathString}
-- "duplicate" can be changed to "move":
--
duplicate file ((systemItems's item i) as string) to ¬
folder (pathString) of folder (targetPath) ¬
with replacing
end tell
end if
end if
end repeat
set AppleScript's text item delimiters to astids
on error e number n from f to t partial result p
set AppleScript's text item delimiters to astids
error e number n from f to t partial result p
end try
end open
if you want to mount a volume try:
mount volume "smb://URL/Volume" as user name "uname" with password "password"
then get a list of the disks
set mounted_Disks to list disks