Pbpaste doesn't seem to work as expected when I run it from a cron job.
I have an applescript that opens a PDF file in Preview and sends it the copy command and then closes Preview. Next I'd like to paste that into a file, pbpaste > pasta.txt. This all works great, when I run it as myself.
However if I put it as a task in crontab -e, it does run correctly and even created the output file, but the contents are empty. It's as if whatever context the running is happening in has a different concept of the clip board.
My crontab is like this:
* * * * * cd /Users/bemmu/Public;osascript yeah.script
And yeah.script is like this:
do shell script "open tiliote.pdf"
delay 2
tell application "Preview"
activate
delay 2
tell application "System Events" to keystroke "a" using {command down}
delay 2
tell application "System Events" to keystroke "c" using {command down}
delay 2
tell application "System Events" to keystroke "q" using {command down}
delay 2
end tell
do shell script "pbpaste > pasta.txt"
Expected result is that pasta.txt would contain the PDF file in text and that is what happens if I run this script by hand. However if cron runs it, pasta.txt gets created but contains nothing (size is 0).
I can see that the copy definitely is successful when run from cron, as I can paste it myself later. It's just that pbpaste doesn't seem to be working from cron.