on
run
set
the pdfImageFolder to
choose folder with prompt "Select a folder of PDF images:"
tell
me to open {pdfImageFolder}
end
run
on open (theFolders)
repeat
with pdfImageFolder in theFolders
repeat 1
times
set
AppleScript's text item delimiters
to {""}
tell
application "Finder"
if
kind of pdfImageFolder
is not "Folder" then exit repeat
set
imageFolderLocation to container
of the pdfImageFolder
set
the pdfImages to (every
file of the pdfImageFolder
whose name extension = "PDF")
end
tell
set
jpgOutputFolder to my EstablishFolder(imageFolderLocation, "PDF and JPG Files")
tell
application "Image Events" to
launch
repeat
with x from 1 to
count of the pdfImages
set
thisFile to
item x of the
pdfImages as alias
tell
application "Finder"
set
thisFileName to the
name of thisFile
set
AppleScript's text item delimiters
to {",_", ",", "_", "-"}
set
thisFileName to text items
of thisFileName
set
AppleScript's text item delimiters
to {"_"}
set
thisFileName to thisFileName
as text
try
set
the name of
thisFile to thisFileName
on
error errMsg
number errNum
--
display dialog errMsg
end
try
end
tell
tell
application "Image Events"
set
the pdfImageReference to
open
thisFile
tell
the pdfImageReference
set
the pdfImageName to
name
set
AppleScript's text item delimiters
to {".pdf"}
set
the pdfImageName to
text item 1 of the pdfImageName
save
in ((jpgOutputFolder
as text) & the
pdfImageName & ".jpg") as
JPEG
end
tell
end
tell
tell
application "Finder" to
move thisFile
to jpgOutputFolder with
replacing
end
repeat
end
repeat
end
repeat
end
open
on EstablishFolder(folderLocation,
myFolderName)
set
newFolderPath to (folderLocation
as string) &
myFolderName
try
repeat
set
newFolderPath to (folderLocation
as string) &
myFolderName
set
existingItem to alias
newFolderPath
tell
application "Finder"
if
kind of existingItem
is "folder" then
return
existingItem
else
if
the last character of
newFolderPath = "ƒ" then error "Can't Make Folder"
set
myFolderName to myFolderName & "ƒ"
end
if
end
tell
end
repeat
on
error errorText number
errNum
tell
application "Finder"
try
make
new folder
at folderLocation
set
NewFolder to the
result as alias
set
the name
of NewFolder to myFolderName
on
error errorText number
errNum
if
errNum = -48 then
return
newFolderPath as
alias
else
display dialog
errorText & return &
errNum
end
if
end
try
end
tell
end
try
return
NewFolder as
alias
end EstablishFolder