Scott
Scott

Reputation: 611

expanding variables inside an Bash script that has a HEREDOC in AppleScript

I have this simple code:

#!/bin/bash

# Where are we going to store these files?
BACKUPSTORE="$HOME/Library/Application\ Support/Evernote-Backups"
/bin/echo "BACKUPSTORE: $BACKUPSTORE"
/bin/mkdir -p "$BACKUPSTORE"
/usr/bin/cd "$BACKUPSTORE"

osascript <<END
-- PURPOSE: Export all notes in Evernote to an ENEX file so that
-- the notes can be backed up to an external drive or to the cloud

-- Change the path below to the location you want the notes to be exported
set f to $BACKUPSTORE

with timeout of (30 * 60) seconds
    tell application "Evernote"
        -- Set date to 1990 so it finds all notes
        set matches to find notes "created:19900101"
        -- export to file set above
        export matches to f
    end tell
end timeout

-- Compress the file so that there is less to backup to the cloud
set p to POSIX path of f
do shell script "/usr/bin/gzip " & quoted form of p
END

I think I am getting an error on:

set f to $BACKUPSTORE

Or possibly on:

set p to POSIX path of f
do shell script "/usr/bin/gzip " & quoted form of p

How do I get the expansion to work, and deal with the spaces in the file path and using escaped spaces or literal quoting as AppleScript wants it?

The error I get in a shell when I ./run it is: 217:218: syntax error: Expected expression but found unknown token. (-2741)

Upvotes: 0

Views: 583

Answers (1)

Barmar
Barmar

Reputation: 780798

You need to put quotes around the string:

set f to "$BACKUPSTORE"

You also don't need to escape the spaces when assigning to BACKUPSTORE, since you have the value in quotes.

Upvotes: 1

Related Questions