Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question
What user does cron use for executing your script? Can you influence that? –  Daniel Beck Dec 9 '10 at 17:38

1 Answer 1

up vote 1 down vote accepted

Why not ditch the script and use an Automator workflow (or compiled app) since they have a dedicated method for extracting text from PDFs into a text file.

enter image description here

You also might try ditching Cron and running your script via a LaunchAgent. Example:


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.