I am writing a script for a service that will get metadata quickly. There must be a better way of getting the file name without the name extension. Any other ideas to clean this up would be appreciated as well.
tell application "Finder"
set thePath to (path to documents folder as text) & "exifdata"
if not (exists thePath) then
do shell script "mkdir -p " & POSIX path of thePath & ""
end if
repeat with i from 1 to count of (selection as list)
set theLocation to POSIX path of (item i of (selection as list) as alias)
set theItem to item i of (selection as list)
set theName to (name of theItem as string)
set theCount to (count of theName) - ((count of (name extension of theItem as string)) + 1)
set theName to text 1 thru theCount in theName
set destLocation to "'" & POSIX path of thePath & "/" & theName & ".txt'"
do shell script "exiftool -a '" & theLocation & "' >" & destLocation
do shell script "open " & destLocation & ""
end repeat
end tell
set thePath to POSIX path of (path to documents folder) & "exifdata"
do shell script "mkdir -p " & quoted form of POSIX path of thePath
tell application "Finder" to set theSelection to selection
repeat with anItem in theSelection
set theLocation to POSIX path of (anItem as text)
set {name:fileName, name extension:nameExtension} to anItem
set baseName to text 1 thru ((get offset of "." & nameExtension in fileName) - 1) of fileName
set destLocation to quoted form of (thePath & "/" & baseName & ".txt")
do shell script "exiftool -a " & quoted form of theLocation & " >" & destLocation
do shell script "open " & destLocation
end repeat
A variation I like (but still using offset) is the one below which can’t be confused by intermediate periods within the name: myFile.new.txt, for example.
set f to (choose file) -- for illustration
tell (info for f) to set {Nm, Ex} to {name, name extension}
set BN to text 1 thru ((get offset of "." & Ex in Nm) - 1) of Nm
BN