2

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 ").

1 Answer 1

1

Alright (wow a significant portion of my recent stack exchange posts have been like this. it's a wonderful rubber ducky)

I was missing the leading Macintosh HD: in the path.

I had everything right. Just needed to set this line to be:

export front document to file ("Macintosh HD:Users:slu:automator-text-export:" & theName & ".txt") as unformatted text
1
  • Well documented questions are amazing for shining a light into the corners of a problem space. Well done and thanks.
    – bmike
    Commented Aug 26 at 14:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .