AppleScript-based rule only works manually

Greetings,
I have set up numerous Rules to automatically move messages to specific folders, based on Subject headers. These work automatically, as new mail comes in.
However, one of my Rules is set up to "Run Applescript." The script deals with a single file that gets e-mailed to me by one of my webservers at 11:00 each night. It deletes the previous night's file from the HD, grabs the new attachment, saves it to the HD, and deletes the message in Mail. The script works correctly, but the Rule (which is set as Active) only works when I select the message and do it manually (Command-Option-L) -- not automatically when the message arrives.
Why is this?
The script, which lives in /Library/Scripts/Mail Scripts/Rule Actions, is below.
Thanks!
DM
<hr>
using terms from application "Mail"
    on perform mail action with messages theMessages for rule theRule
        tell application "Mail"
            repeat with thisMessage in theMessages
                set theAttachment to first item of thisMessage's mail attachments
                set theAttachmentFile to theAttachment's name
                tell application "Finder"
                    if exists "iBook:Users:me:Documents:" & theAttachmentFile then
                        delete "iBook:Users:me:Documents:" & theAttachmentFile
                    end if
                end tell
                save theAttachment in "iBook:Users:me:Documents:" & theAttachmentFile
                delete thisMessage
            end repeat
        end tell
    end perform mail action with messages
end using terms from

I would start by verifying that the rule is in fact firing - add a set color of background action before the run applescript action.
Next I would try a few magic incantations:
change the script location to ~/Library/Scripts/Applications/Mail/
remove the "for rule theRule" from the on perform
add an on run handler after the end of the existing script
using terms from application "Mail"
on run
tell application "Mail" to set sel to selection
tell me to perform mail action with messages (sel)
end run
end using terms from
Why? 'cos any scripts that I have successfully run from a rule are like that! The 3rd one has the advantage that you can apply your script to selected messages, which can be useful (though not in the present case).
If none of this works, it is time to try some serious debugging. You could consider putting in an try ... on error with a display dialog for the error message, or simply a display dialog on script entry to verify that it is running.
Let me know ...
AK

Similar Messages

  • Outlook 2010 rules only run manually

    Hello All,
    I have a user whose Outlook 2010 rules only run manually. He has some server rules and he has some that say client only next to them. All of the client side rules are listed under the server rules. I have deleted all of his rules and had him recreate them
    and i've ran outlook /cleanrules and they still do not work. I'm not sure what to try next. We are running Exchange 2010 Standard and Outlook 2010. Any ideas?
    Thanks,
    Alex

    I had this same problem, tried many things that said it would work and didn't. Here's how I fixed it:
    There are several good programs that backup Outlook. Backup FIRST.... I use Outback Plus 9 (http://ajsystems.com/outbackplus/obp.html) and there's also BackupOutlook (http://www.backupoutlook.com/)
    Backup Outlook using Outback 9 Plus then:
    1 - Go to the Control Panel
    2 - In the Search box - enter:  
    Mail
    3 - Run the Mail 
    - or -  Mail (32 bit) applet
    4 - Click: 
    Show Profiles
    5 - Select the profile (you likely have only one)
    6 - Click: 
    Remove    [this will remove the registry settings for this profile]
    7 - Close the Control Panel
    8 - Run Windows Explorer
    9 - Go to the: 
    [My Documents]\Outlook Files  folder
    10 - Delete the \Outlook Files folder (or delete all of the items in it)
    11 - Go to the folder  
    c:\users\--your user name--\appdata\local\Microsoft\outlook
    12 - Delete all of the files in this folder
    13 - Go to the folder:  
    c:\users\--your user name--\appdata\roaming\Microsoft\outlook
    14 - Delete all of the files in this folder
    This gets rid of the Outlook data and the profile setting.
    I would restore the Outlook data (using OutBack Plus 9 - and assuming you have at least one POP3 type account) as follows:
    1 - Run OBP9 and click Restore
    2 - Locate the backup file to restore from  
    -- Open it
    3 - When you get the message indicating that a full profile restore will not be done - acknowledge it.  
    OBP9 should then be planning to do a "Default" restore (i.e. it will restore the data to the default locations). 
    4 - Select the Outlook data files for the restore ... but do NOT restore any ".ost" type files (Outlook will rebuild these automatically).
    5 - Finish the restore -- this will restore the Outlook data files to the proper default locations (e.g. 
    [My Documents]\Outlook Files for normal ".PST" files)
    6 - Start Outlook [which will begin with a request to create a new Profile (Outlook) then email account]
    7 - Refer to the web page:  
    http://ajsystems.com/kb3/outlook2010emailaccounts.htm
    and begin at step "B" ... by electing to do a manual configuration of the account.
    8 - Link the account to the (appropriate) Personal Folder file [PST file] restored to [My Documents]\Outlook Files
    9 - Add any other POP3 type accounts using the same procedure .. linking them to the appropriate PST file. 
    Note - you can have multiple POP3 account linked to the same Personal Folder file (as was always the case prior to Outlook 2010.
    10 - Add any other accounts (e.g. IMAP based accounts) which will automatically create the appropriate file and re-synch with the server.
    11 - Re-run OBP9
    12 - Locate the backup file to restore from  
    -- Open it
    13 - Select Outlook Profile settings and ancillary settings (e.g. Signatures) ... but do NOT select any PST or OST files.
    14 - Finish the restore to restore these settings to the new profile (created by step 6).
    This was done with Outlook 2013 as well and on Windows 7 and Windows 8.1.  All worked!

  • [SOLVED] Custom udev rule only working when triggered manually

    I have the following rule created for a USB gamecube controller adapter:
    SUBSYSTEMS=="usb", ATTRS{idVendor}=="057e", ATTRS{idProduct}=="0337", MODE="0666"
    This rule only takes effect when I run udevadm trigger AFTER my device is plugged in. If I then unplug the device, and plug it back in, my device no longer works. My device also doesn't work on boot. I have to plug my device in and then trigger the rules manually.
    Any ideas why this is happening? I don't want to have to run udevadm trigger every time I turn my computer on.
    Last edited by Exershio (2015-04-15 23:01:19)

    I tried reloading the configuration but it doesn't affect the issue. As for monitoring udev, this appears when I plug the device in:
    KERNEL[3439.476646] add /devices/pci0000:00/0000:00:12.0/usb4/4-5 (usb)
    KERNEL[3439.478441] add /devices/pci0000:00/0000:00:12.0/usb4/4-5/4-5:1.0 (usb)
    KERNEL[3439.486155] add /devices/pci0000:00/0000:00:12.0/usb4/4-5/4-5:1.0/0003:057E:0337.0009 (hid)
    KERNEL[3439.492319] add /class/usbmisc (class)
    KERNEL[3439.492497] add /devices/pci0000:00/0000:00:12.0/usb4/4-5/4-5:1.0/usbmisc/hiddev0 (usbmisc)
    KERNEL[3439.492602] add /devices/pci0000:00/0000:00:12.0/usb4/4-5/4-5:1.0/0003:057E:0337.0009/hidraw/hidraw0 (hidraw)
    UDEV [3439.493842] add /class/usbmisc (class)
    UDEV [3439.494832] add /devices/pci0000:00/0000:00:12.0/usb4/4-5 (usb)
    UDEV [3439.496365] add /devices/pci0000:00/0000:00:12.0/usb4/4-5/4-5:1.0 (usb)
    UDEV [3439.498256] add /devices/pci0000:00/0000:00:12.0/usb4/4-5/4-5:1.0/usbmisc/hiddev0 (usbmisc)
    UDEV [3439.498378] add /devices/pci0000:00/0000:00:12.0/usb4/4-5/4-5:1.0/0003:057E:0337.0009 (hid)
    UDEV [3439.499567] add /devices/pci0000:00/0000:00:12.0/usb4/4-5/4-5:1.0/0003:057E:0337.0009/hidraw/hidraw0 (hidraw)
    So it seems udev is detecting the GC adapter being plugged in, but it doesn't apply permissions 0666 to it until I manually run udevadm trigger.
    See what happens below, directly after plugging it in:
    $ ls -l /dev/bus/usb/004/005
    crw-rw-r-- 1 root root 189, 388 Apr 15 16:59 /dev/bus/usb/004/005
    $ sudo udevadm trigger
    $ ls -l /dev/bus/usb/004/005
    crw-rw-rw- 1 root root 189, 388 Apr 15 17:03 /dev/bus/usb/004/005
    Okay this is weird. So I appended my udev rule with GROUP="users" to see if that would help, and after reloading the rules, this happens after my device is plugged in:
    $ ls -l /dev/bus/usb/004/005
    crw-rw-r-- 1 root users 189, 393 Apr 15 17:32 /dev/bus/usb/004/005
    $ sudo udevadm trigger
    $ ls -l /dev/bus/usb/004/005
    crw-rw-rw- 1 root users 189, 393 Apr 15 17:34 /dev/bus/usb/004/005
    So it appears the device is taking on GROUP="users" immediately after being plugged in, but it wont set MODE="0666" until after running udevadm trigger
    Anyone have any ideas?
    Last edited by Exershio (2015-04-15 21:38:15)

  • Mail redirect rule only works with "every message"?

    I have been trying to redirect selected mail from a pop account to another email address. it only seems to work if I select the Every Message condition. If I try to use a condition like "From Contains Newberg" in the rule, the mail is not redirected.

    Thanks for the welcome!
    Ok so here are some screenshots...
    Here is the screenshot of the rule details
    Here is the main rules window
    And here is a screenshot showing how some are redirected and some are not (the ones that are redirected (and the one that shows the forward icon (it was forwarded before I set up the redirect rule)) are all from the same domain as my email account.
    Any ideas? Thanks!

  • Mail Forward Rule Not Working

    I have a few mail forwarding rules set which don't seem to be working. I see no forwarded emails in my send mailbox, and when I click the small arrow in the message window that indicates it has been forwarded, I get a message that says I must have deleted the message, which is not true. This is what the rule looks like:

    Mail rules only work on incoming mail. Once the mail is listed in your Inbox, the only way to use a rule is to manually run it. Given how rules work this may render your rule as non-working.

  • [PLEASE HELP] How to get Microsoft Outlook Rules to work on my Z10

    Hi, 
    My organization recently started deploying Z10 for work. We use Mircosoft Outlook 2010 and I receive many e-mails throughout the day that I filter by setting up rules. 
    These Outlook rules do not seem to transferr over to my Z10 e-mail account as I am being constantly flooded with these "junk" e-mails. 
    I've tried to change the folder sync settings, but that doesn't seemt to rectify the problem. 
    I have Software Release 10.2.0.429 and OS Version 10.2.0.1803
    Does anyone in this community know about this problem and if there's a solution? 
    Thanks so much. 
    - Kyle 

    DoubleK wrote:
    Hi, 
    My organization recently started deploying Z10 for work. We use Mircosoft Outlook 2010 and I receive many e-mails throughout the day that I filter by setting up rules. 
    These Outlook rules do not seem to transferr over to my Z10 e-mail account as I am being constantly flooded with these "junk" e-mails. 
    I've tried to change the folder sync settings, but that doesn't seemt to rectify the problem. 
    I have Software Release 10.2.0.429 and OS Version 10.2.0.1803
    Does anyone in this community know about this problem and if there's a solution? 
    Thanks so much. 
    - Kyle 
    Unfortunately Outllok rules only work within Outlook itself.
    One way that I have found to partially work is to use the IMAP server (if available in your organisation) from both the computer and the device(s), and to keep Outlook running while you are gone, and then the rules works for most of them
    Using the Playbook and the Z10 and the Z30 and loving them
    Martin

  • I added a contact to my iphone 4s and when I did a sync manually it is not showing up on my MAC in address book - please help....I checked off sync all contacts in iTunes  - does it only work one way from computer to phone?

    I added a contact to my iphone 4s and when I did a sync manually it is not showing up on my MAC in address book - please help....I checked off sync all contacts in iTunes  - does it only work one way from computer to phone?

    Is it because the new itunes looks different.
    View > Show Sidebar
    Then it should work just the same as on your old computer.

  • Hello all,  I bought an iPhone 5 in the US and brought it back to Brasil. Now I'm trying to use Siri, but once I press the "home" button "voice control" appears and it only works for me to call my contacts. The manual guide tells me to go to Settings Gene

    Hello all,
    I bought an iPhone 5 in the US and brought it back to Brasil. Now I'm trying to use Siri, but once I press the "home" button "voice control" appears and it only works for me to call my contacts. The manual guide tells me to go to Settings>General>Siri. At the General menu "Siri" doesn't appear. What should I do to set Siri up if it doesn't appear at settings>general?
    Thank you,
    Melanie.

    Go to Settings>General>Restrictions and make sure Siri is set to On.

  • Ipw3945 only working when modprobing manually / not on startup

    The last kernel update broke my wireless.
    When booting, the ipw3945d daemon will tell me "ERROR: Could not find Intel PRO/Wireless 3945ABG Network Connection". After it finishes booting, I can rmmod the ipw3945 module and modprobe it again. Starting the daemon after that works flawlessly. Even if I try to start the daemon manually after the booting sequence, I'll get that error. I first need to rmod and modprobe ipw3945 for it to work. So...:
    [21:32:40 | shapeshifter@Tachycineta ~]$ sudo /etc/rc.d/ipw3945d start
    :: Starting IPW3945d                                                                                                [BUSY]
    2008-03-01 21:32:47: ERROR: Could not find Intel PRO/Wireless 3945ABG Network Connection
                                                                                                                                  [DONE]
    [21:32:48 | shapeshifter@Tachycineta ~]$ sudo rmmod ipw3945
    [21:32:50 | shapeshifter@Tachycineta ~]$ sudo modprobe ipw3945
    [21:32:53 | shapeshifter@Tachycineta ~]$ sudo /etc/rc.d/ipw3945d start
    :: Starting IPW3945d                                                                                                [DONE]
    [21:32:57 | shapeshifter@Tachycineta ~]$
    And I have no idea why it only works when modprobing manually.
    Anyone?
    Last edited by TB2 (2008-03-01 23:05:33)

    zenlord wrote:
    Are you sure it's driver-related? I have never heard anyone complain about deassociating wireless networks unless they were using networkmanager or wicd or something like that. In the various threads about netcfg2 I have never seen anyone with this problem.
    Zl.
    I don't know if it's driver-related, but it could be power-related: iwl3945 isn't able to retrieve my ap essid everytime, since on the other hand ipw3945 is able to do, with the laptop in the SAME position.
    Last edited by uastasi (2008-03-13 20:10:18)

  • Applescript mail rule

    I am trying to write a Applescript rule for Mail. The rule is triggered when a Mail with a specific title arrives. Here is the script that gets triggered.
    <script>
    using terms from application "Mail"
              on perform mail action with messages theMessages
                        tell application "Finder" to set pathToAttachments to (path to desktop folder as string)
                        tell application "Mail"
                                  repeat with theMessage in theMessages
                                            if theMessage's mail attachments is not {} then
                                                      repeat with theAttachment in theMessage's mail attachments
                                                                set theFileName to pathToAttachments & (theMessage's id as string) & space & theAttachment's name
                                                                try
      save theAttachment in theFileName
                                                                on error errnum
                                                                end try
                                                      end repeat
                                            end if
                                            tell application "Preview" to open theFileName
                                            tell application "Finder" to delete theFileName
                                  end repeat
                        end tell
              end perform mail action with messages
    end using terms from
    </script>
    Okay, the actual script actually tells NeatWorks to open theFileName, but most people do not have NeatWorks, and the problem occurs with Preview also.
    So, the rule works if the mail message is selected, run after the mail has arrived. I would like the rule to automatically run when the message first arrives. But the script doesn't trigger.
    My other rules that are not based Applescript run when a message first arrives. Does anyone know why?

    It might be a threading issue, but I am not sure it is as you think.
    I do see a likely threading error with Applescript with  Services. I set up a Speak Service using Automator; it speaks the selected text. I have set that up on a Keyboard shortcut. If I invoke the Speak Service, it runs fine. If I invoke the Speak Service a second time while the first block of text is being read, The speak block continues to execute proprerly, but I get a Workflow Error for the second block of selected text. My guess, as you stated, is Applescript is not re-entrant and that generates the error. 
    If the mail problem were a threading issue, I would expect the rule to work the first time but fail the second time the rule got invoked. The rule does not even run properly the first time or the only time the rule gets invoked.
    It maybe a threading error in so far as the rule gets triggered as soon as the rule is detirmined to be true, but the piece of mail might not be completely loaded. With the imcoplete message, the Applescript cannot completely and correctly check the email.
    This is further supported by the fact, if the mail is executed on the e-mail as a lone piece of mail in the Inbox, The Applescript rule runs as expected.

  • I am traveling in Chile, South America. I purchased an Entel sym card and I can make and receive phone calls, but the internet only works on WiFi. Do I need to region unlock or what? I willl only be here for A month and a half so I don't want to buy a pho

    I am traveling in Chile, South America. I purchased an Entel sym card and I can make and receive phone calls, but the internet only works on WiFi. Do I need to region unlock or what? I willl only be here for A month and a half so I don't want to buy a phone. Any suggestions?

    Most of the current Apple Intel based computers are comparable in CPU speed. I don't think it is so much the model of laptop as it is the memory, and storage capacity of the machine. If you are going to use FCP on a regular basis, perhaps as a professional or semi-professional, then you should think about the maximum memory and a very large capacity internal disk drive. For instance, one hour of finished compressed video will take up about 1.5 to 2Gbytes of disk space. If you add up the raw footage and still imagery and audio, you'll use up your disk drive capacity real quick. So a hard disk on the order of 750Gbytes @ 7200rpms might be good for video editing. 5400RPMs might be slow to rendering times. Rendering a video might take up a lot of memory so more memory is better e.g. 8Gbytes.
    As a rule of thumb, once you get to about 80% of your disk drive or memory you'll see degradation of performance.
    You can check out macsales.com. THey have a menu system that will allow you to pick and choose from various alternatives. BTW, it's been said that although Macs are typically spec'd at a certain memory size, macsales.com found that Apple computers will actually support higher memory levels. That is, if 4Gbytes are spec'd, some machines support 6Gbytes. macsales.com will provide the guidance for you.
    You might also consider buying an external disk e.g. 500Gbytes to carry around with you for back-up or transport to another machine.

  • How to create LDAP filter-based rule to check Group membership in OAM

    Hi folks,
    I'm having hard time creating an authorization rule to verify ldap group membership. I've followed "Configure User Authorization" article from Oracle website (http://download.oracle.com/docs/cd/E10761_01/doc/oam.1014/b32420/v2authz.htm#BABHBFEJI) and created an Authorization scheme w ldap_attribute_name as User Parameter and ruleExpression as Required Parameter. Then, inside my policy I created an Authorization Rule based on my Authz scheme w Allow Access attrib filter-based Rule which looks like this:
    ldap://ldap_server:port/ou=People,o=Company,c=US??sub?(ldap_attribute_name=ldap_attribute_value)
    This works fine.
    Now, I've added another filter-based rule under the same Authz Rule/Allow Access:
    ldap://ldap_server:port/ou=Groups,o=Company,c=US?uniqueMember?sub?(&(objectClass=groupOfUniqueNames)(cn=ldap_group_name))
    While query looks somewhat correct and works as a command-line argument (slightly modified format), it does not work in OAM (meaning people w out req-d group membership can still login).
    Can someone steer me to the right direction as to what do I need to do:
    1. Change/fix the ldap query
    2. Create new Authz scheme with uniqueMember userParameter; create new Authz rule based on new authz scheme; create new Allow Access filter rule with the ldap query I have
    3. Do smth else
    Any help is greatly appreciated.
    Thank you, Roman

    You can create two authorization rules
    First for user with attribute
    and second for group
    and then in authorization expression you can have AND of these two.
    Regarding your query...
    First ... If your requirement is to give access to all the members of a particular group then you don't require any ldap filters
    All you have to do is in the authorization rule -> Allow access -> Select People (here you have to select group so click on the group tab, its little hard to see but its there in light blue color on dark blue tab) -> select the group you want to give access
    Second.. If your requirement is such that you want to give access to a member of a group which has certain attribute lets say group with status active ( In this case you are not aware of the name of the group because user can be a member of any group but you want to give access only to the group with specific attribute.) then you have to write custom authorization plugin.
    If the option is second let me know i can give you a solution which will work for a single domain without any effort of developing a major plugin.
    Hope this helps,
    Sagar

  • Rules not working in Outlook 2010 Sent Items folder (Personal Folder)

    I've been trying to automatically categorize and send emails I've written and sent to the archive's Sent Items folder.  However, everytime I create a rule for a particular type of email it doesn't carry it out.  The rule will only work when I manually
    click 'Run this rule now...'.
    Here is what my rule looks like:
    Apply this rule after the message arrives
    from Byron33
      and sent to 'XXX'
      and with 'YYY' in the subject'
    assign it to the 'ZZZ' category
      and move it to the Sent Items folder (here, 'Sent Items' is in the Archive section)
    But it doesn't work.  All my other rules work (for the inbox folder).  Any way in which I can get this rule to function automatically?

    Hi
    Thank you for using
    Microsoft Office for IT Professionals Forums.
    From your description, I understand that the rule will only work when you manually click 'Run this rule now...'. If there is any misunderstanding,
    please feel free to let me know.
    Turn off Cached Exchange Mode to test this issue:
    http://office.microsoft.com/en-us/outlook-help/turn-on-or-off-cached-exchange-mode-HP010355560.aspx?CTT=1
    Click the File tab.
    Click Account Settings, and then click Account Settings.
    On the E-mail tab, click the Exchange account, and then click
    Change.
    Under Microsoft Exchange server, clear the Use Cached Exchange Mode check box.
    Exit and then restart Microsoft Outlook 2010.
    If it work fine after turn off cached exchange mode ,please repair your .OST file follow this article steps:
    http://office.microsoft.com/en-us/outlook-help/repair-outlook-data-files-pst-and-ost-HA010354964.aspx?CTT=1
    More additional information
    Troubleshoot rules you can refer to this link:
    http://office.microsoft.com/en-us/outlook-help/troubleshoot-rules-HP005242904.aspx?CTT=1
    Similar thread you can refer this link:
    http://www.msoutlook.info/question/133
    Please Note: Since the web site is not hosted by Microsoft, the link may change without notice. Microsoft does not guarantee the accuracy of this
    information.
    Please take your time to try the suggestions and let me know the results at your earliest convenience. If anything is unclear or if there is anything
    I can do for you, please feel free to let me know.
    Hope that helps.
    Sincerely
    William Zhou CHNPlease remember to mark the replies as answers if they help and unmark them if they provide no help.

  • Delete rule not working

    I subscribe to a mailing list using a particular email address (not my primary account), all mail for which is redirected into a mailbox. I only want to keep messages from the last five days. I have a Rule which is set as follows:
    If ALL of the following conditions are met:
    Account = <the account>
    Date Received is Greater Than 5 days old
    Perform the following actions:
    Delete Message
    This rule does does not work. It is the first rule in my list of Rules. And it simply does nothing. Why?

    Maxplanar,
    Mail rules only run when the item is first processed. So you are in effect going to delete things only when they are received in an "old" state.
    I would set up a smart mailbox or two. One to only show the 5 days of mail you want to pay attention to. Optionally make another smart mailbox to contain messages older than 5 days. You can just refer to the first mailbox and only see the messages you want. The other mailbox will be there for once a month when you select all the messages and delete them.
    Most macs can handle 5 to 10 thousand messages without even starting to slow down. Perhaps once you have a managable folder that shows you the messages you care to see, you can live with manually cleaning up much less often?

  • Mobility group only works using management interface?

    Hello,  in order to stablish the control traffic between 2 WLC-5508, it's necessary to use the management interface??
    It's possible using a dynamic interface o service port ?
    I think it only works with management interface,  but I don't understand the meaning of this text in the Configuration Manual:
    "Mobility control packets can use any interface address as the source, based on routing table."
    Thank you,

    No... mobility communication is done only with the management interface.
    Thanks,
    Scott
    *****Help out other by using the rating system and marking answered questions as "Answered"*****

Maybe you are looking for