I am writting a script that adds a DVD number to an excel sheet. The DVD number depends on the fileName passed through.
At the moment 80 images are on a dvd. I have a script that does this, gets the dvd number, but if the namber passed is 80 then the returned answer after the script is run is 2, but should be 1. Same on each number that is a multiple of 80.
Help please cheers guys.
on getDVD(fileName)
--back up the old settings
set oldDelims to AppleScript's text item delimiters
try
--as some files have a * just before the -
if fileName contains "a*" then
set AppleScript's text item delimiters to {"a*"}
else if fileName contains "*" then
set AppleScript's text item delimiters to {"*"}
else --cretae new applescript delimiter settings
set AppleScript's text item delimiters to {"-"}
end if
--set number to division by 80, return without decimel
set num to (((text item 1 of fileName) as number) / 80) div 1
--set the delimiters back to the original
set AppleScript's text item delimiters to oldDelims
--return the value of DVD
return (num + 1)
on error theError
--set applescripts delimiters back to originals
set AppleScript's text item delimiters to oldDelims
display dialog "An error occured: " & return & theError buttons {"Cancel"}
end try
end getDVD
the filename format is:
002451-CF.jpg
so 000080-CF.jpg should be 1 but returns 2.
on getDVD(fileName)
--back up the old settings
set oldDelims to AppleScript's text item delimiters
try
--as some files have a * just before the -
if fileName contains "a*" then
set AppleScript's text item delimiters to {"a*"}
else if fileName contains "*" then
set AppleScript's text item delimiters to {"*"}
else --cretae new applescript delimiter settings
set AppleScript's text item delimiters to {"-"}
end if
--set number to division by 80, return without decimel
set num to round (((text item 1 of fileName) as number) / 80) rounding up
--set the delimiters back to the original
set AppleScript's text item delimiters to oldDelims
--return the value of DVD
return num
on error theError
--set applescripts delimiters back to originals
set AppleScript's text item delimiters to oldDelims
display dialog "An error occured: " & return & theError buttons {"Cancel"}
end try
end getDVD