I’m trying to write an AppleScript that includes a “do shell script” command. The script is intended to work on selected files on the desktop, reading a date from each file and then using the file contents to make a new entry in the Day One journal program using the date. The form of the Day One CLI is this:
dayone -d=“” new < ~/Desktop/
Unfortunately, however I write this script, I get an error:
error “Finder got an error: sh: ~/Desktop/11-9.txt: No such file or directory” number 1
(My test files are currently called 11-9.txt and 11-10.txt, but I’ve also experienced the problem using other file names.)
Here are the scripts I’ve tried. At first, I named the files with the date (e.g., “November 9, 2014”), which the CLI can interpret. The following script yields the error above in the ScriptEditor Result window.
tell application "Finder"
activate
set theseItems to selection
repeat with thisItem in theseItems
set thePath to thisItem as string
set theAlias to thisItem as alias
set theDate to name of theAlias
do shell script "dayone -d=" & quoted form of theDate & " new < \"~/Desktop/" & theDate & "\""
end repeat
end tell
The following variation brings up a ScriptEditor alert:
Finder got an error: sh: :Users:john:Desktop:11-9.txt: No such file or directory
And when I tried another tack, reading the date (in form “11/09/2014”) from the top of the file contents, I got the same error as just above:
tell application "Finder"
activate
set theseItems to selection
end tell
repeat with thisItem in theseItems
tell application "Finder"
set thePath to thisItem as string
set fp to open for access file thePath
set theDate to read fp until "4"
close access fp
end tell
do shell script "dayone -d=" & quoted form of theDate & " new < " & quoted form of thePath
end repeat
Why is my script not finding the files? What am I missing?
TIA.
Model: MacBook Pro (early 2011)
AppleScript: 2.4
Browser: Safari 600.1.25
Operating System: Mac OS X (10.8)