Hi all,
I have found this great script in the scriptbuilders section from Nathan Olson to extract the IPTC-info of TIFF files. Now I am trying to make a droplet of it so I can extract the captions of many files at once and write name and caption to a text file.
However I can’t figure out why it isn’t working. Can I get some help here?
- No textfile is made
- The script doesn’t extract the caption since I changed the first line of Nathans script (see below)
Thanks for helping me out,
Kjeld
on open fileList
set captionFileList to (((path to desktop) as string) & "Captions.txt") as file specification
repeat with oneFile in fileList
set captionFile to {}
set fileName to the name of oneFile
--From here starts Nathan Olsons script which is working perfect for one file.
--set tiffFile to (choose file with prompt "Select tif file: " of type {"TIFF"}) as string
set tiffFile to oneFile as string
set refToFile to open for access file tiffFile
set imageFileHeader to (read refToFile from 1 to 8)
set ifhList to {}
repeat with i from 1 to 8
set ifhList to ifhList & (ASCII number (character i of imageFileHeader))
end repeat
if (item 1 of ifhList) = 77 then
set ifdList to reverse of (items -1 thru -4 of ifhList)
else
set ifdList to (items 5 thru 8 of ifhList)
end if
set ifdStart to ((my listToNumb(ifdList)) + 1)
set dirEntries to (read refToFile from ifdStart to ifdStart + 1)
if (item 1 of ifhList = 77) then
set deList to {ASCII number (character 2 of dirEntries), ¬
ASCII number (character 1 of dirEntries)}
else
set deList to {ASCII number (character 1 of dirEntries), ¬
ASCII number (character 2 of dirEntries)}
end if
set numDirectories to my listToNumb(deList)
set fileInfoEntry to ifdStart + 2
set foundDirectory to false
repeat with i from 1 to numDirectories
set checkBytes to (read refToFile from fileInfoEntry to fileInfoEntry + 1)
if (checkBytes = "ªÉ") or (checkBytes = "ɪ") then
set foundDirectory to true
exit repeat
end if
set fileInfoEntry to fileInfoEntry + 12
end repeat
if not (foundDirectory) then ¬
display dialog ¬
"Cutline not available." buttons "Cancel" default button 1
set fiOffset to (read refToFile from (fileInfoEntry + 8) to (fileInfoEntry + 11))
if (item 1 of ifhList = 77) then
set fiList to {ASCII number (character 4 of fiOffset), ¬
ASCII number (character 3 of fiOffset), ¬
ASCII number (character 2 of fiOffset), ¬
ASCII number (character 1 of fiOffset)}
else
set fiList to {ASCII number (character 1 of fiOffset), ¬
ASCII number (character 2 of fiOffset), ¬
ASCII number (character 3 of fiOffset), ¬
ASCII number (character 4 of fiOffset)}
end if
set fiOffset to my listToNumb(fiList)
set checkChar to (read refToFile from (fiOffset + 10) to (fiOffset + 12))
if not (character 1 of checkChar is "x") then ¬
display dialog ¬
"Caption not available." buttons "Cancel" default button 1
set captionCount to (text 2 thru 3 of checkChar)
set captionList to {ASCII number (character 2 of captionCount), ¬
ASCII number (character 1 of captionCount)}
set captionLength to my listToNumb(captionList)
set captionStart to fiOffset + 13
set captionEnd to captionStart + captionLength - 1
set the_Caption to (read refToFile from captionStart to captionEnd)
close access refToFile
--End of Nathan Olsons script
copy (fileName & the_Caption & return) to end of captionFile
end repeat
end open
try
open for access the_file with write permission
set eof of the_file to 0
write (captionFile) to the_file starting at eof as list
close access the_file
on error
try
close access the_file
end try
end try
on listToNumb(theList)
set retNumb to 0
repeat with i from 1 to (count of theList)
set retNumb to retNumb + (item i of theList) * (256 ^ (i - 1))
end repeat
return retNumb
end listToNumb