hi, i am new to applescript, scripting in general, and to the macscripter forums.
I am trying to use applescript to run a shell script which ( using jpeg2pdf - http://koan.studentenweb.org/software/jpeg2pdf.html ) prompts for a directory, in my case a directory full of jpg’s, and creates a PDF from all of the images.
The script in its entirety basically does this.
- prompt user for time of the stock release
- prompt user to choose a directory (which contains images of the items in the stock release)
- copies the contents of the chosen directory to a network drive (where another script is running constantly - checking for new files, and if there are any new files, copying them securely over the internet to an external location)
- notifies people via Adium that there as been a stock release
- builds an email message with number of items in the folder, time of the stock release, signature, etc. Then attach the folder chosen in step 2 to the message.
- Use Mail Scripts 2.7.11 ( http://homepage.mac.com/aamann/Mail_Scripts.html ) to schedule delivery of the email to people working remotely
[b]7) compile PDF using jpeg2pdf with images from the directory chosen in step 2 <— haven’t made it there yet. - print multiple copies of the PDF <— haven’t made it there yet. [/b]
Now, I need to compile a PDF using jpeg2pdf. The PDF needs to contain all of the images from the folder chosen in step 2. Then I will try to use some applescript to print multiple copies of this PDF. Here’s where I ran into my worries.
-- Prompt for whether an attachment is desired. If so, prompt for the location of the file.
set theResult to display dialog "Please attach stock release folder!" buttons {"Yes", "No"} default button 1
set wantsAttachment to button returned of theResult
if wantsAttachment is equal to "Yes" then
tell application "Finder"
set theAttachment to choose folder
count files in folder theAttachment
set numFiles to result & " items."
end tell
end if
-- Create PDF using jpeg2pdf
set fileInfo to do shell script "cd ~/Documents/SRPDF/; ls;" & "jpeg2pdf " & theAttachment & " SR.PDF"
set fileInfo to do shell script "echo $PATH"
The error I receive is this –
/usr/bin/jpeg2pdf:34:in `require’: No such file to load – optparse (LoadError)
from /usr/bin/jpeg2pdf:34
I have seen the error before… when I was initially trying to get jpeg2pdf working. The problem was that my path was not set correctly, and jpeg2pdf can not use the default ruby install that comes with os x 10.3.
I had to set my path correctly, and I had to install ruby 1.8.2. Now, through the terminal jpeg2pdf works OK. But through applescript, it doesn’t.
Working OK, it will say something like this… (here I have not compiled any images into a PDF)
glenm:~ glenm$ jpeg2pdf
Usage: jpeg2pdf [options]
Options:
-r, --recursive Process directories recursively
-a, --all Process al files, including hidden files
-v, --verbose Give more output
-h, --help Show usage information
-V, --version Show version
Now.
echo $PATH in the terminal results in
/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/bin:/sbin:/usr/bin:/usr/local/bin:/usr/sbin
set fileInfo to do shell script "echo $PATH"
results in
/usr/bin:/bin:/usr/sbin:/sbin:/Users/glenm
Has anyone seen this before? I wonder which file applescript is referencing to when it tries to determine what the path is set to?
[b]
[/b]
Edit: Apologies. I searched through the forum and found some code that works fine. Thanks everyone.
set scriptPath to quoted form of POSIX path of (theAttachment)
set fileInfo to do shell script "cd ~/Documents/SRPDF/; " & "jpeg2pdf " & scriptPath & " SR.PDF"
I can paste the full script if anyone is interested aswell. It’s a bit messy.
Thanks for reading this far, any help is much appreciated.