Previous 1 2 3 4 5 Next 68 Replies Latest reply: Jul 30, 2013 2:30 AM by Nick Williams1 Go to original post
  • twtwtw Level 5 Level 5 (4,900 points)

    2point5 wrote:

     

    Oh.... does anyone know of a really good Applescript reference book that defines what all the commands do and also provides some examples?

     

    AppleScript Language Guide.  Fee and downloadable.

  • 2point5 Level 3 Level 3 (955 points)

    Thanks baltwo.

  • 2point5 Level 3 Level 3 (955 points)

    Thanks twtwtw.  I did in fact find that one shortly after I posted the question.

  • softwater Level 5 Level 5 (5,370 points)

    baltwo wrote:

     

    AppleScript 1-2-3, by Soghoian & Cheeseman would be your best bet. The others I know about are a bit dated.

     

    I'll second that recommendation. Both a learning guide and a reference manual. It's over 800 pages and costs as little as $20.

  • eberlepatric Level 1 Level 1 (0 points)

    A friend made a script that worked perfect an OS Lion, but on Mountain Lion, we have trouble.

    The goal is to printout from specified e-mail-adress the attached-pdf, and store this pdf in a special folder.

    The rule looks like this:

    Bildschirmfoto 2013-07-06 um 16.48.34.png

    On Lion, the code for IMAP and POP worked was with the new term, suggested by Tony T1:

    -- diesen Pfad überprüfen, muss existieren!

    property savePdfTo : "SSD Empfang:Users:mpa:elexiseingang:Arztberichte"

     

    -- nicht ändern (muss immer gleich bleiben für Growl)

    property THIS_APP_NAME : "SaveAndPrintAttachement"

     

    -- main entry point of mail app

    --on perform_mail_action(ruleData)

    using terms from application "Mail"

              on perform mail action with messages theMessages for rule theRule

     

                        try

      -- growl integration

                                  my registerWithGrowl()

     

      -- The folder to save the attachments in (must already exist)

                                  set attachmentsFolder to savePdfTo as rich text

     

      -- The downloads folder

                                  set downloadFolder to ((path to home folder) as rich text) & "Downloads"

     

      -- Get incoming messages that match the rule

                                  tell application "Mail"

      --set selectedMessages to |SelectedMessages| of ruleData

                                            repeat with theMessage in theMessages

     

      -- Save the attachment

                                                      repeat with theAttachment in theMessage's mail attachments

    ......

     

     

    On Mountain Lion, the whole code like this works manually everytime, by receiving e-mails sometimes for IMPA and never for POP, looks like this:

    -- diesen Pfad überprüfen, muss existieren!

    property savePdfTo : "SSD Empfang:Users:mpa:elexiseingang:Arztberichte"

     

    -- nicht ändern (muss immer gleich bleiben für Growl)

    property THIS_APP_NAME : "SaveAndPrintAttachement"

     

    -- main entry point of mail app

    --on perform_mail_action(ruleData)

    using terms from application "Mail"

              on perform mail action with messages theMessages for rule theRule

     

                        try

      -- growl integration

                                  my registerWithGrowl()

     

      -- The folder to save the attachments in (must already exist)

                                  set attachmentsFolder to savePdfTo as rich text

     

      -- The downloads folder

                                  set downloadFolder to ((path to home folder) as rich text) & "Downloads"

     

      -- Get incoming messages that match the rule

                                  tell application "Mail"

      --set selectedMessages to |SelectedMessages| of ruleData

                                            repeat with theMessage in theMessages

     

      -- Save the attachment

                                                      repeat with theAttachment in theMessage's mail attachments

                                                                set originalName to name of theAttachment

                                                                set downloadSavePath to downloadFolder & ":" & originalName

                                                                set savePath to attachmentsFolder & ":" & originalName

                                                                try

      -- speichern

      save theAttachment in downloadSavePath

     

      -- datei verschieben

                                                                          my movefile(downloadSavePath, attachmentsFolder)

     

      -- drucken

                                                                          my printfile(savePath)

     

      -- meldung anzeigen

                                                                          my displayGrowlMessage("Fax empfangen", "Ein Fax wurde am " & theMessage's date sent & " empfangen, ausgedruckt und im Ordner 'Arztberichte' abgelegt.")

                                                                on error msg

                                                                          display dialog "Fehler: " & msg buttons {"OK"} default button 1 with title "Fehler beim Faxempfang"

                                                                end try

                                                      end repeat

                                            end repeat

                                  end tell

     

                        on error msg

                                  display dialog "Fehler: " & msg buttons {"OK"} default button 1 with title "Fehler beim Faxempfang"

                        end try

     

              end perform mail action with messages

    end using terms from

    --end perform_mail_action

     

    -- Adds leading zeros to date components

    on pad(n)

              return text -2 thru -1 of ("00" & n)

    end pad

     

    -- I am moving the given file

    on movefile(filepath, targetpath)

     

      -- move via the command line

              set cmd to "mv -f " & quoted form of (POSIX path of filepath)

              set cmd to cmd & " " & quoted form of (POSIX path of targetpath)

              set cmd to cmd as «class utf8»

      do shell script cmd

     

    end movefile

     

    -- I am printing the given file with the chosen application

    on printfile(filepath)

     

      -- printing via the command line

              set cmd to "lpr " & quoted form of (POSIX path of filepath)

              set cmd to cmd as «class utf8»

      do shell script cmd

     

    end printfile

     

    (*

    Growl Funktionen

    *)

    on isGrowlRunning()

              tell application "System Events"

                        (count of (every process whose bundle identifier is "com.Growl.GrowlHelperApp")) > 0

              end tell

    end isGrowlRunning

     

    on registerWithGrowl()

     

              if isGrowlRunning() then

                        tell application id "com.Growl.GrowlHelperApp"

      -- Make a list of all the notification types

      -- that this script will ever send:

                                  set the allNotificationsList to {"Info"}

     

      -- Make a list of the notifications

      -- that will be enabled by default.     

      -- Those not enabled by default can be enabled later

      -- in the 'Applications' tab of the growl prefpane.

                                  copy the allNotificationsList to the enabledNotificationsList

     

      -- Register our script with growl.

      -- You can optionally (as here) set a default icon

      -- for this script's notifications.

      register as application THIS_APP_NAME ¬

      all notifications allNotificationsList ¬

      default notifications enabledNotificationsList ¬

      icon of application "Mail"

                        end tell

              end if

    end registerWithGrowl

     

    on displayGrowlMessage(growlTitle, growlText)

              if isGrowlRunning() then

                        tell application id "com.Growl.GrowlHelperApp"

      notify with name "Info" title growlTitle description growlText application name THIS_APP_NAME

                        end tell

              else

      display dialog growlText buttons {"OK"} default button 1 with title growlTitle

              end if

    end displayGrowlMessage

    Sometimes a see this error:

    Bildschirmfoto 2013-07-06 um 16.54.48.png

     

    Do you have suggestion for changing the code?

    Thanks in advance!

  • niwrik Level 1 Level 1 (0 points)

    Did you ever get the Devonthink rules working in your environment?  I have the exact same issue in a MBP with two drives where user profiles are not on the system drive.  I used a symlink to point to the user folder on the second drive.

  • eberlepatric Level 1 Level 1 (0 points)

    I tried the rule, and it works, the pdf is in the inbox!

     

    -- Mail Rule - Add attachments to DEVONthink Pro.

    -- Created by Christian Grunenberg on Fri May 18 2012.

    -- Copyright (c) 2012-2013. All rights reserved.

     

    using terms from application "Mail"

              on perform mail action with messages theMessages for rule theRule

                        tell application "Mail"

                                  set theFolder to (POSIX path of (path to temporary items))

                                  repeat with theMessage in theMessages

                                            set theSender to the sender of theMessage

                                            repeat with theAttachment in mail attachments of theMessage

                                                      try

                                                                set theFile to theFolder & (name of theAttachment)

                                                                tell theAttachment to save in theFile

                                                                tell application id "com.devon-technologies.thinkpro2"

                                                                          set theAttachmentRecord to import theFile to incoming group

                                                                          set URL of theAttachmentRecord to theSender

                                                                end tell

                                                      end try

                                            end repeat

                                  end repeat

                        end tell

              end perform mail action with messages

    end using terms from

  • niwrik Level 1 Level 1 (0 points)

    Thanks for your input.  Unfortunately (for me), that's the default script I have that doesn't work on my MBP.  It works fine on my iMac (both 10.8.4).  My MBP has 2 hard disks (one for system, one for user profiles) and uses a symlink to point the users folder to the 2nd drive.  This is what triggers the error.  Something to do with Sandboxing...

     

    My temporary workaround is to collect the attachments from incoming e-mails on the iMac and then sync the databases with Dropbox.  I hope this will only be temporary...

     

    Here's the error from the system log:

     

    7/9/13 1:40:49.883 PM Mail[21641]: Failed execution of AppleScript: /Users/niwrik/Library/Application Scripts/com.apple.mail/Mail Rule - Add attachments to DEVONthink Pro.scpt

    Error Domain=NSCocoaErrorDomain Code=257 "The file “Mail Rule - Add attachments to DEVONthink Pro.scpt” couldn’t be opened because you don’t have permission to view it." UserInfo=0x7fcbc21590e0 {NSURL=file://localhost/Users/niwrik/Library/Application%20Scripts/com.apple.ma il/Mail%20Rule%20-%20Add%20attachments%20to%20DEVONthink%20Pro.scpt, NSLocalizedFailureReason=Script file is not in the application scripts folder.}

  • Nick Williams1 Level 1 Level 1 (5 points)

    Hi All.

     

    I know next to nothing about Apple Script but I rely heavily on folder action scripts. Mine stopped working after upgrading to Mountain Lion too, but I found that if I attached two instances of the script to the folder it worked reliably always. I get the action occurring twice but that's not an issue for me since the folder is emptied of the relavent file by the 1st action. Maybe tweaking your scripts so that having it run twice wouldn't be a problem. Hope this helps.

Previous 1 2 3 4 5 Next