I have the following applescript as the sole component of an Automator app:
on run {input, parameters}
repeat with theFile in input
tell application "Pages"
set theDoc to open theFile
set theDocName to name of theDoc
-- I implemented the sanitization of spaces to underscores in hope of fixing this present issue but it has not helped.
set sanitizedDocName to do shell script "echo " & quoted form of theDocName & " | sed -e 's/ /_/g'"
set theName to sanitizedDocName & "-auto-text"
display dialog (":Users:slu:automator-text-export:" & theName & ".txt")
export front document to file (":Users:slu:automator-text-export:" & theName & ".txt") as unformatted text
close theDoc saving no
end tell
end repeat
return input
end run
I think the intention is self-explanatory. I can use the snippets I already found online to ask finder for the path the input file was from, e.g.:
tell application "Finder"
-- Actually theFilesFolder is unused here
set theFilesFolder to (folder of theFile) as text
end tell
This snippet works to successfully export to a place relative to the files' original positions.
But I specifically want to make all my exports go into a predermined hardcoded directory, but I'm failing here on where I can find documentation on how to build a proper AppleScript representation of a filesystem location. I've also tried assembling the path with just slashes instead of colons but it makes for a different kind of error ("Could not be exported as ").