Apple script to open an attachment

Hi all,
Can someone help me writing an appleScript to open an attachment of a mail.
I want to create a rule in Mail that when ever I get an email with a specific attachment it will be opened. I plan to run this script whenever mail is receiving an email with this attachment.
Thanks,
Ziv

I run this from the script menu, so you will need to tidy it up and modify it for your rule.
AK
<pre style="font-family: 'Monaco', 'Courier New', Courier, monospace; overflow:auto; color: #222; background: #DDD; padding: 0.2em; font-size: 10px; width:400px">on saveAttachments(messageList, theAttachmentPath, FolderName)
set attachmentCount to 0
set WhoSentStuff to "" -- going to stick names in a text file later
tell application "Mail"
repeat with eachMessage in messageList
-- check for attachments  
try
set theHeaders to all headers of eachMessage
set AppleScript's text item delimiters to "multipart/mixed"
if number of text items in theHeaders > 1 then -- check for attachments...  
set theSource to source of eachMessage
set AppleScript's text item delimiters to ""
set Userid to my GetUserid(sender of eachMessage)
set WhoSentStuff to WhoSentStuff & Userid & return
set tempFileName to Userid & " Attachments"
set tempFile to theAttachmentPath & tempFileName
open for access file tempFile with write permission
set eof file tempFile to 0
write theSource to file tempFile as string
close access file tempFile
tell application "StuffIt Expander" to expand {alias tempFile} into alias theAttachmentPath with delete originals
tell application "Finder"
set theFolders to get (every folder in alias theAttachmentPath whose name is (tempFileName & " Folder"))
if (count of theFolders) = 1 then
set thePath to theAttachmentPath & tempFileName & " Folder"
else
set thePath to theAttachmentPath
end if
delete (every file in alias thePath whose name starts with tempFileName & ".attachment")
-- rename file to userid, move it up
set FileList to every file in alias thePath
-- count existing files from this student
set FileIndex to count of (every file in alias theAttachmentPath whose name begins with Userid)
repeat with ThisFile in FileList
set FileName to Userid
if FileIndex > 0 then set FileName to FileName & "." & FileIndex
set FileIndex to FileIndex + 1
set name of ThisFile to FileName & "." & name extension of ThisFile
set attachmentCount to attachmentCount + 1 --count extractions
end repeat
move (every file in alias thePath) to alias theAttachmentPath
if (count of every file in alias thePath) = 0 then
delete alias thePath
end if
end tell
end if -- multipart/mixed message  
on error TheError
display dialog Userid & " -- " & TheError
end try
end repeat
end tell
tell application "Finder"
set DidItFile to open for access theAttachmentPath & FolderName & "-DidItLog" with write permission
write WhoSentStuff to DidItFile starting at eof
close access DidItFile
end tell
return attachmentCount
end saveAttachments
on GetUserid(FullEmail)
(** Return 1st word of email address after <, otherwise just 1st word **)
set WhoDunIt to words of FullEmail
repeat until WhoDunIt does not contain "<"
set WhoDunIt to rest of WhoDunIt
end repeat
return item 1 of WhoDunIt
end GetUserid
</pre>

Similar Messages

  • Is there a script to open an attachment within a PDF in a separate window?

    I have a PDF with a button to open an attachment. I know that in my preferences I can set it always open in a separate window, but not all users know to do this. Is there a script to make this happen? I have a script to open links in a separate window, but not an attachment.

    This can't be done with a script, but you can do it manually by going to
    the link you created, editing the "Go to a page in another document" action
    in it and then setting the "Open in" option to "New Window".
    This can also be done with a stand-alone tool, but that is more
    complicated, of course.

  • Apple Script For Opening External EML File With Apple Mail

    Hi folks,
    

 I am working with Apple Script for implementing numerous function related to Mail App.
    

I am using the following Apple Script lines for opening the mails which are in Mail app for each modes.
    

View Mode : open theMsg

    Reply View Mode : reply theMsg opening window yes

    Reply All Mode : reply theMsg opening window yes reply to all yes

    Forward Mode : forward theMsg opening window yes



    I want to know how we can open external eml file in different view modes (View, Reply, Reply All and Forward) using Apple Script or Apple Event programmatically with a similar mechanism available through script in Mail App.

    
Thanks in advance.

Regards
    
Nisar

    I'm not sure what you're doing here, but this isn't anything I recognize as compilable applescript. what is this 'mode' thing you're talking about.
    at any rate, if you have a loose emlx file sitting around somewhere you can simply open it in mail (use the 'open' command and the file specification for the emlx file) and work with it appropriately. if you're talking about an actual eml file (e.g. from Outlook Express) you'd have to GUI script Mail's 'import mailbox' command (the applescript handler for importing mail only works with Mail.app mailboxes)

  • Apple script to open Outlook 2011 issues

    Hello,
    I am trying to write a apple script to launch some applications in bulk, not necessarily always at startup. The application I am having trouble with is Microsoft Outlook because it brings a pop up window asking if I want to turn on office reminders. I of course want to turn them on, can I set the apple scrip to click the turn on button? And can I set the apple script to make sure on startup the reminders are turned on each time I start Outlook. Your help is much appreciated.

    Hello,
    I am trying to write a apple script to launch some applications in bulk, not necessarily always at startup. The application I am having trouble with is Microsoft Outlook because it brings a pop up window asking if I want to turn on office reminders. I of course want to turn them on, can I set the apple scrip to click the turn on button? And can I set the apple script to make sure on startup the reminders are turned on each time I start Outlook. Your help is much appreciated.

  • Using c++ variable in apple script

    Hi all,
    I am just calling the apple script from my indesign plugin.
    I need to pass the c++ variable to apple script for opening a file
    This in my apple Script which i have embedded in c++ code
    tell application "TextEdit"
    activate
    open "Users:User1:Library:Preferences:Adobe Indesign:Version 5.0:MathEQ.txt"
    end tell
    The filepath "Users:User1:Library:Preferences:Adobe Indesign:Version 5.0:MathEQ.txt" is stored in the C++ variable char* textFileName.
    I need to use the variable textFileName in apple script which has the path.
    How to go about it?
    Thanks
    Sakthi

    I have a similar problem trying to get data from any field into an AppleScript variable.
    Something like *set phoneNumber to cell "Phone Number" of current record* works fine if you are using the script from a layout that has this field on it.
    But I have a lot of fields on different layouts and I want to have access to all fields in the table, no matter what layout they are on, or what layout is currently active.
    And I want to do this without having to specify on what layout each field is located.
    In the past (FileMaker 6) I used something like *set phoneNumber to (cell "Phone Number" of current record of database 1)* but this is no longer working in FileMaker 9.
    So I was thinking to use something like *set phoneNumber to cell "Phone Number" of current record of table "Table Name"* but that doesn't seem to work.
    The only thing that seems to work is *set phoneNumber to cell "Phone Number" of current record of layout "Layout Name"* but as I said, I don't want to specify the layout for each field.
    Any ideas anyone?
    Message was edited by: khasmir

  • Script to open an pdf attachment in the adobe form is not working.

    Hello Experts,
    I have a requirement where i should open pdf attachment from the attachment tab of adobe form.
    For this i have written below  java script in the click event of a button ->
    I have an attachment pdf with name attach.pdf in the attachment tab of adobe form.
    var oObj = event.target;
    oObj.openDataObject();
    ->When i click on the button it is giving the error -> TypeError: Invalid Argument type.
                                                                                    Parameter cName.
    Can any one help me how can i use openDataObject method to open an attachment from the attachment tab of adobe form.
    Regards,
    Menaka.H.B
    Moderator message: wrong forum, please post again in Adobe Interactive Forms.
    Edited by: Thomas Zloch on Oct 18, 2010 12:52 PM

    Hi,
    Please refer to the thread below where this issue has been discussed:
    Creative cloud wants to make changes
    Regards,
    Sheena

  • Open multi page pdf specific page in Illustrator CS4 with apple script

    I need to open multi page pdf specific page in Illustrator CS4 with apple script. Is it something like this:
    activate  (open file theTargetFolder as PDF with options …).
    Thank you.

    Carlos,
    Muchas Gracias por tu colaboración y excelente script, el que se abra el ESTK no tiene mayor importancia.
    El caso es que Adobe recomienda encarecidamente NO utilizar Illustrator para editar PDFs, por diversas razones, aunque cuando no hay otro remedio o herramienta disponible, o conocida ...
    Para llegar aquí, aparte de San Google, hay que ir a Adobe.es (en mi caso), pestaña de Ayuda,  ..... (hasta aqui bien),
    luego hay que bajar hasta el final y ver Comunidad y Foros...... (esto puede ser)
    al pulsar aparacen un montón de foros se supone de programas pero en inglés,
    y la última línea es de International Forums,  ya casi hemos llegado)
    pulsamos entonces, y por fin se abren cuatro palabras con idiomas, en una dice: español      (casi no me lo puede creer)
    pincho y llego por fin aquí.
    Muy poca gente sabe de la existencia de este pequeño refugio, si a esta dificultad añadimos la peculiar forma de ser de la gente, ....

  • Apple script for Message box when Mail app Compose Window Opens

    Hi there
    I'm trying to make mail app remind me to choose the right emaill address to send from since I have several email addresses. Is there a way I can make or write an apple script for a message box to pop up whenever mail app's compose window opens up.
    I can do for the case when I actally click the compose button when I'm on mail app by using UI scripting. But when it comes to hyperlinks which opens up the compose window, it fails.
    I just want a script to see whether the compose window is open and if open pop up a message box.
    Thanks
    Best regards
    Zam Shabeer Thahir

    TaoChitpol wrote:
    By the way, the problem happens with the account of MS Exchange service, I don't know if this is the cause of the problem.
    I think yes.  The encoding is being corrupted somewhere, probably Exchange.  There is nothing you can change on the iPad other than the OS languagel, to see if that helps.  You can also tell Apple at
    http://www.apple.com/feedback/

  • Is it possible to set a files label on opening via apple script?

    Hi,
    I would like to mark files which have been opened with i.e. a red lable.
    Would that be possible using apple script?
    If yes how would that script look like?
    Thanks in advance.

    I don;t know of anyway of doing this in Applescript. There is the ability to monitor files using launchd, WatchPaths,  but you need to know the files your monitoring before hand so it won't work for this.
    Again if the domain is limited, that is it's only a certain application or a certain folder you're interested in it might be possible to put something together in Applescript but as a general use, system wide, solution I don;t think it can be done.
    One other possibility would be to use the Finder and smart folders. You could look for all files in a certain folder or system wide that have been acessed in the past period and then mark those. Something along those lines is doable with eiter the Finder or a script.
    regards

  • I can not open email attachment which is sent from a swann dvr using apple mail since i upgraded to Yosemite ,has anyone got a fix ? the file format is _mnt_tmp_

    i can not open email attachment which is sent from a swann dvr using apple mail since i upgraded to Yosemite ,has anyone got a fix ? the file format is _mnt_tmp_

    Oh no... NOT THE 99-PAGER!!! Anything but THAT!!!

  • Apple has sent out several updates lately for the OS. Now I cannot open ANY attachment to ANY e-mail. Is there a fix?

    Apple has sent out several updates lately for the OS. Now I cannot open ANY attachment to ANY e-mail. Is there a fix?

    Microsoft Office 365 is a subscription - based service. You have to pay for it... and keep paying for it... and paying for it... as in 365 days a year... or lose your hard work.
    Office Home Premium is a mere $10 a month, but a convenient annual subscription is only $100 a year. This is a substantial discount to Microsoft's Office 365 business products ($150 / employee / year).
    Such a deal! Are you not absolutely thrilled?
    Here are some slightly more reasonable alternatives, all of which are compatible with their Office equivalents:
    LibreOffice (donation-supported)
    NeoOffice ($10 but older version is free if you can find it)
    OpenOffice (completely free)
    Numbers ($19.99)
    Pages ($19.99)

  • HT2128 I have an email purportedly from Apple store which I am sure is spam or a virus. I have not opened the attachment. Is there anywhere I can send it?

    I have an email purportedly from Apple store which I am sure is spam or a virus. I have not opened the attachment. Is there anywhere I can send it?

    They aren't going to do anything, and they have no place to which you can send it. Put it in the Trash and forget about it.

  • Open & close iTunes every night via Apple Script

    What I would like to do is have my Mac come out of sleep at 3am, open iTunes and download all my podcasts and then go back to sleep. Is this possible with Apple Script?

    In System Preferences>Energy Saver click on 'Schedule' and set 'Start Up or Wake' to 3 AM
    In iCal set up an event for 3.05, setting an alarm to Open File and selecting iTunes.
    Suppose you want to allow half an hour:
    In AppleScript Editor, write
    tell application iTunes to quit
    tell application "Finder" to sleep
    and save it somewhere as a script, not an application.
    Set up an event in iCal for 3.35 with an alarm, setting it to Run Script and selecting your script.

  • Apple Script to make Pages open in a user-selected screen position

    This is a follow-up to a response/script made previously by Yvan KOENIG that enables Pages to open a Pages template in a user-selected "left" position.
    http://discussions.apple.com/message.jspa?messageID=9100331#9100331
    This works great for me, but I'd like to take this one step further, if possible. I'm naïve when it comes to Apple Scripts
    Currently, if I use the script, it opens up in 100% 'fit-width' view as follows:
    http://trials.sent.com/pages/100.png
    What I'd like it to do is to open up in 125% 'fit-width' view as follows:
    http://trials.sent.com/pages/125.png
    I'd like to therefore ask if it's possible to somehow enable this in the script above.

    I looked at the English version.
    Let me say you that you are a funny guy.
    Set width and set "Fit Width" are incompatible commands.
    On my 1920 x 1200 screen, if I set scale to 125%, Fit Width is disabled.
    If I check "Fit width", the size remains unchanged but is no longer selected.
    On a smaller display, "Fit Width" will set the page in the "100%" mode.
    My guess is that it's what you get.
    As I am a good guy,
    I add some instructions in the code.
    Now you may activate several settings to fit your needs (when they are technically compatibles).
    --(SCRIPT openToLeft.app]
    Enregistrer le script en tant que Script, Application ou Progiciel : openToLeft.xxx
    déplacer l'application créée dans le dossier
    <VolumeDeDémarrage>:Users:<votreCompte>:Library:Scripts:Applications:Pages:
    Il vous faudra peut-être créer le dossier Pages et peut-être même le dossier Applications.
    menu Scripts > Pages > openToLeft
    Le script créera un nouveau document à partir du modèle choisi et le poussera à gauche de l'écran.
    --=====
    L'aide du Finder explique:
    L'Utilitaire AppleScript permet d'activer le Menu des scripts :
    Ouvrez l'Utilitaire AppleScript situé dans le dossier Applications/AppleScript.
    Cochez la case "Afficher le menu des scripts dans la barre de menus".
    +++++++
    Save the script as a Script, an Application or an Application Bundle: openToLeft.xxx
    Move the newly created application into the folder:
    <startup Volume>:Users:<yourAccount>:Library:Scripts:Applications:Pages:
    Maybe you would have to create the folder Pages and even the folder Applications by yourself.
    menu Scripts > Pages > openToLeft
    The script will create a new document from the selected template and will push it to the screen's left edge.
    --=====
    The Finder's Help explains:
    To make the Script menu appear:
    Open the AppleScript utility located in Applications/AppleScript.
    Select the "Show Script Menu in menu bar" checkbox.
    +++++++
    Yvan KOENIG (Vallauris FRANCE)
    4 mars 2009
    property theApp : "Pages"
    property hardCoded : false
    true = the template is predefined
    false = you select the template when you run the script *)
    property zoomIt : false
    false = leaves the doc size as created
    true = issue a cmd + > command to enlarge it *)
    --=====
    on run
    my activateGUIscripting()
    tell application "Pages"
    set Templates_loc to localized string "Templates" (* nom local du dossier "Modèles" *)
    set MyTemplates_loc to localized string "My Templates" (* nom local du dossier "Mes Modèles" *)
    end tell -- theApp
    set templatesFolder to ((path to application support from user domain as text) & "iWork:Pages:" & Templates_loc & ":" & MyTemplates_loc & ":")
    if hardCoded then (*
    Here the template to use is hard coded in the script *)
    if templatesFolder does not end with ":" then set templatesFolder to templatesFolder & ":"
    set myTemplate to (templatesFolder & "un modèle09.template:") as alias
    else (*
    Here we are urged to choose the template in a dialog *)
    set templatesFolder to templatesFolder as alias
    Don't ask me why, Pages uses two Universal Type Identifiers for its templates
    the first one is used if only Pages '08 is installed under 10.4 or by both '08 and '09 under 10.5.6
    the second one is used under 10.4.11 if Pages '09 is installed *)
    set allowed to {"com.apple.iWork.Pages.template", "com.apple.iWork.Pages.sfftemplate"}
    if 5 > (system attribute "sys2") then
    set isOs4 to true
    set permitted to allowed
    else
    set isOs4 to false
    set permitted to {}
    end if
    if my parleAnglais() then
    set myTemplate to choose file "Choose a Pages template …" of type permitted default location templatesFolder
    else
    set myTemplate to choose file "Choisissez un modèle Pages …" of type permitted default location templatesFolder
    end if
    if not isOs4 then
    due to a system's bug, choose file is unable to filter the iwork's files UTIs
    So we must check by ourself *)
    set maybe to myTemplate as text
    tell application "System Events" to set typid to type identifier of disk item maybe
    if typid is not in allowed then
    if my parleAnglais() then
    error "The file “" & maybe & "” is not a Pages template !"
    else
    error "Le fichier « " & maybe & " » n’est pas un modèle Pages !"
    end if
    end if
    end if
    (* Here, the pathname of the template is of class alias *)
    end if -- hardCoded
    try
    tell application "Pages"
    activate
    set n to count of documents
    open myTemplate (* create a new doc from the template *)
    repeat
    if (count of documents) > n then
    exit repeat
    else
    delay 0.1
    end if
    end repeat
    tell window 1 (*
    As we are telling to application "Pages" we may use tell window 1 even if we have an Inspector or a Find/Replace dialog open.
    It would be wrong if we where telling to process "Pages" *)
    set {x1, y1, x2, y2} to get bounds
    set bounds to {0, 0, x2 - x1, y2 - y1} (* move the window to the left edge *)
    set view scale to 125.0
    --set fit page to true (* or false *)
    set fit width to true (* or false *)
    --set full screen to true (* or false *)
    --set outline visible to true (* or false *)
    --set ruler visible to true (* or false *)
    --set styles visible to true (* or false *)
    --set thumbnails visible to true (* or false *)
    --set toolbar visible to true (* or false *)
    --set two up to true (* or false *)
    end tell -- window
    end tell -- application
    end try
    end run
    --=====
    on activateGUIscripting()
    tell application "System Events"
    if not (UI elements enabled) then set (UI elements enabled) to true (* to be sure than GUI scripting will be active *)
    end tell
    end activateGUIscripting
    --=====
    on parleAnglais() (* Check if Pages is running in French *)
    local z
    try
    tell application theApp to set z to localized string "Cancel"
    on error
    set z to "Cancel"
    end try
    return (z is not "Annuler")
    end parleAnglais
    --=====
    --[/SCRIPT]
    Yvan KOENIG (from FRANCE jeudi 14 mai 2009 11:35:36)

  • Acrobat script to open attachment panel

    Hi!
    Is there a way to open one of the panels when a pdf is opening?
    I have forms (livecycle ES) that users can attach pdf to. I would like that when the form is sent to the next person in the flow. I open the attachment panel in reader, so that the user can see attachments
    I have a method to check if attachments have been added, so if not possible, I can add a big textbox to check attachment panel.. but the other way would be better
    soo come on.. give me your great ideas
    /Thomas Groenbaek, Jyske Bank

    Please repost in the LiveCycle forms forum.

Maybe you are looking for

  • Spool file error - Buffer Overflow

    I've a sql script that is running from a.sql file. The script fetches almost 9 million data as a result of the query. Main problem is related to spool file generation. It is saying buffer overflow. But, when i write that query from sql prompts it is

  • My screen is white, why?

    I was charging my IPod Touch and when I tried to use it the screen turned white. None of my applications are showing.  What happened?  I only have a blank white screen?

  • Using macbook pro, how do I create and print labels

    how do I create and print labels using macbook pro

  • Server 4.0.3 website problems

    Ever since I installed Server 4.0.3, all of my virtual domains were wiped out.  When I recreate them, it goes to the default Apache "It Works!" page rather than the directory I specify in the GUI config.  Additionally, it is doing this for the Server

  • How do I retrieve a deleted text message from my i cloud backup?

    I deleted a  text message today and need to get it back. My i phone was backed up last night to the cloud but I can't figure out how find the message. Help!