Applescript: Copy File Names into an Email

*I've been slowly teaching myself Applescript, and can't seem to find a way to do a few things. Basically what I'm trying to do is set up a script that will run when items are dropped into a folder on my FTP. I want the script to have a pop-up dialogue, and generate an email to certain users announcing new files are on the FTP. I have these 2 parts down, but I would also like the body of the email to include a list of the filenames. This part I can't figure out.*
*I just need to find a function that will copy the filenames of new items, and paste them into the body of the email already being generated. My current code is below. Anyone have any ideas to help me expand?*
property dialog_timeout : 15 -- set the amount of time before dialogs auto-answer.
on adding folder items to this_folder after receiving added_items
try
tell application "Mail"
set theMessage to make new outgoing message with properties {visible:true, subject:"New Files on FTP", content:"New files have been posted to incoming folder of the FTP."}
tell theMessage
make new to recipient at end of to recipients with properties {name:"Jane Doe", address:"[email protected]"}
make new to recipient at end of to recipients with properties {name:"John Smith", address:"[email protected]"}
end tell
send theMessage
end tell
tell application "Finder"
--get the name of the folder
set the folder_name to the name of this_folder
end tell
-- find out how many new items have been placed in the folder
set the item_count to the number of items in the added_items
--create the alert string
set alert_message to ("Folder Actions Alert:" & return & return) as Unicode text
if the item_count is greater than 1 then
set alert_message to alert_message & (the item_count as text) & " new items have "
else
set alert_message to alert_message & "One new item has "
end if
set alert_message to alert_message & "been placed in folder " & «data utxt201C» & the folder_name & «data utxt201D» & "."
set the alert_message to (the alert_message & return & return & "Would you like to view the added items?")
display dialog the alert_message buttons {"Yes", "No"} default button 2 with icon 1 giving up after dialog_timeout
set the user_choice to the button returned of the result
if user_choice is "Yes" then
tell application "Finder"
--go to the desktop
activate
--open the folder
open this_folder
--select the items
reveal the added_items
end tell
end if
end try
end adding folder items to
Message was edited by: markeze

AppleScript forum under OS X Technologies.

Similar Messages

  • Copy file names into New Mail Message?

    *I've been slowly teaching myself Applescript, and can't seem to find a way to do a few things. Basically what I'm trying to do is set up a script that will run when items are dropped into a folder on my FTP. I want the script to have a pop-up dialogue, and generate an email to certain users announcing new files are on the FTP. I have these 2 parts down, but I would also like the body of the email to include a list of the filenames. This part I can't figure out.*
    *I just need to find a function that will copy the filenames of new items, and paste them into the body of the email already being generated. My current code is below. Anyone have any ideas to help me expand?*
    property dialog_timeout : 15 -- set the amount of time before dialogs auto-answer.
    on adding folder items to this_folder after receiving added_items
    try
    tell application "Mail"
    set theMessage to make new outgoing message with properties {visible:true, subject:"New Files on FTP", content:"New files have been posted to incoming folder of the FTP."}
    tell theMessage
    make new to recipient at end of to recipients with properties {name:"Jane Doe", address:"[email protected]"}
    make new to recipient at end of to recipients with properties {name:"John Smith", address:"[email protected]"}
    end tell
    send theMessage
    end tell
    tell application "Finder"
    --get the name of the folder
    set the folder_name to the name of this_folder
    end tell
    -- find out how many new items have been placed in the folder
    set the item_count to the number of items in the added_items
    --create the alert string
    set alert_message to ("Folder Actions Alert:" & return & return) as Unicode text
    if the item_count is greater than 1 then
    set alert_message to alert_message & (the item_count as text) & " new items have "
    else
    set alert_message to alert_message & "One new item has "
    end if
    set alert_message to alert_message & "been placed in folder " & «data utxt201C» & the folder_name & «data utxt201D» & "."
    set the alert_message to (the alert_message & return & return & "Would you like to view the added items?")
    display dialog the alert_message buttons {"Yes", "No"} default button 2 with icon 1 giving up after dialog_timeout
    set the user_choice to the button returned of the result
    if user_choice is "Yes" then
    tell application "Finder"
    --go to the desktop
    activate
    --open the folder
    open this_folder
    --select the items
    reveal the added_items
    end tell
    end if
    end try
    end adding folder items to

    Try beginning your script like this:
    on adding folder items to this_folder after receiving added_items
    try
    set theFileNames to ""
    tell application "Finder"
    repeat with thisItem in added_items
    set theFileNames to theFileNames & name of thisItem & return
    end repeat
    end tell
    tell application "Mail"
    set theMessage to make new outgoing message with properties {visible:true, subject:"New Files on FTP", content:"New files have been posted to incoming folder of the FTP:" & return & return & theFileNames}
    It should work.

  • Linux file name into ODI variable

    Hello All,
    I have a situation where we have files in one directory in linux ,I want to import the file name into a ODI variable.
    Ex : A_B_C_2014_01_20.zip (inside this zip file are the flat files with data) is the file name in /u02/source_files location , i want this into a ODI variable and once the data loading is complete ,i want to log it saying
    A_B_C_2014_01_20.zip complete
    A_B_C_2014_01_21.zip complete.
    So my other shell script will look for the complete flag and copy the next file into the ODI pick up location.In this case I need to pick up A_B_C_2014_01_22.zip and start the data loading.
    How do i implement this functionality in ODI. Please let me know.

    Issue was due to a syntax error. Case closed.
    Thanks!
    -OS

  • Feature Request: Ultrabeat: Load Sample auto copy file name to Drum Voice

    Feature Request: Ultrabeat: Load Sample auto copy file name to Drum Voice
    I wish that when I load a sample into a drum voice, that it would automatically copy the name of the sound file I'm importing to the drum voice minus the extension. If I were importing BD01.wav I'd like for the drum voice to display BD01. As it is, I have to import the file, then name or rename the drum voice to BD01. When importing large quntities, this becomes a giant pain, and I'm looking for anything programmatic that could save me a load of time. When I think of all the time I'm going to waste...and if you multiply that by all the number of users...that's a lot of wasted time.
    I wish of course that the program could suck up and autoload all of the sound files within a directory, names too, until the voices were full. Then I could just fine tune and kick out ones I don't want or want in different order. Not a big deal for users who are importing from all kinds of different sources, but say for impoting libraries like NI's Battery, it's a big deal.
    Maybe these could be choices in the load sample menu.
    powerbook G4   Mac OS X (10.4.4)  
    pb g4   Mac OS X (10.4.4)  

    Microsoft pulled the plug on DirectSound HAL in Vista due to lack of hardware support. The SAL exists for
    software compatibility, good intention but bad performance as there is no longer a direct path from
    DirectSound to audio drivers.
    People choose DirectSound for its Direct-ness
    but there is no reason to choose it now.
    DirectX SDK was integrated
    with WIndows SDK which ships with Visual Studio 2012 so you don't need additional downloads for
    WASAPI and XAudio 2.
    Just look up the documentation for headers/librarieslike every other Windows API you use. If you have a hard time to find the documentation then you need to go to search engines and find search engine tutorials. 
    There are plenty of samples for both WASAPI and XAudio 2, both in the Windows SDK and online. The DirectX team has some suggestions on which to use on their team blog.
    You can find experts for those APIs at the Windows Desktop Pro-Audio Application Development forum and the
    Audio/XACT forum on MSDN (link left out for you to practice your search skills). Again, it is fine to ask for hints but don't ask the whole
    solution. You are competing with others who just need a hint to finish work here. The time spent on working on your assignment would be better spent on helping on giving hints to others. 
    Visual C++ MVP

  • Get the file name into a Odi variable

    Hi,
    I need to get the file name into odi variable like ..A/ETC/file.txt
    For eg.the filename file.txt should get store in a variable.
    Then i want to compare the file name stored in the variable with some other value.
    Please suggest.
    Thanks.

    in package,
    declare the variable, then evaluate it with another variable, generally using # syntax
    if the variable is date type, suggest to use : syntax, because # will treat the variable value as text value
    in loadplan
    use case when syntax,

  • Load Source File Names into Recordset Object

    Hi,
    I have a folder with abc.txt, xyz.txt, pqr.txt etc files.
    My requirement is to load all the file names into a Record Set which I need to use in data flow.  I think I need to use For each loop container with Enumerator as 'Foreach File Enumerator' and in the variable mappings I have added a variable name
    to get the file name. But I have stuck how to add these file names to a Record Set target. Please help me.
    Thanks.

    Hi Amaya14,
    Go these this link Click Here
    Thanks

  • Sharepoint Workflow : how to get document full path + file name into variable?

    Hi,
    Anybody knows how to get document full path + file name into a variable in Sharepoint 2010 workflow?
    Example http://sp1:80/InvoiceQueue/Shared Documents/123.pdf
    I am using List Workflow which links to a document library.

    Hi SAMSUNG,
    According to your description, my understanding is that you want to get the full path of a document in a list workflow.
    You can set the variable to the Enconded Absolute URL of the document. The screenshot is my testing. In my testing (in the red area), when the title of a document was equal to the tile of the current item, set a variable to the Enconded Absolute URL of the
    document. I used ‘Log to history list’ to check the value of the variable in Workflow History .
    I hope this helps.
    Thanks,
    Wendy
    Wendy Li
    TechNet Community Support

  • Copy File name and Date only from a Folder with SSIS

    Hello all,
    I need to create a package which will list the file names and the dates in a folder, these files are blank flat files. After extracting the file names from the file path i need to create a table which will have two columns Filename and
    Date.We get about 1000 such files every month and we are looking to maintain them in a table.
    Is this possible? Can someone point me in the right direction? 
    FM

    Arthur , I actually figured it out. The For each container let me pass thru the file name, then I inserted the file name into my staging table. I created a FilePath variable and basically Did a sql task and
    INSERT INTO MyTable
    SELECT Filename = ?,
    LoadDate = GetDate()
    In my for each loop I added a *.*txt qualifier... I`ve tested and works well... Got what I needed.
    FM

  • Script to insert file name into keywords field of same file

    Hello,
    search a solution, a Script or another, which writes the file name into keywords field of same file (Metadata: Description/Keywords) in "photoshop", "bridge" or better in "Lightroom" .
    I found this topic from Mike Hale http://www.ps-scripts.com/bb/viewtopic.php?t=1330
    It's possible this script to change this in such a way that it does this:
    "script to insert file name into keywords field of same file"
    Thanks and best greetings
    Wolfgang

    This works in CS2:-
    #target bridge
       if( BridgeTalk.appName == "bridge" ) {
    nameDescription = MenuElement.create("command", "AddName to Description", "at the beginning of Thumbnail");
    nameDescription .onSelect = function () {
         nameToDescription();
    function nameToDescription(){
    var items = app.document.selections;
          for (var i = 0; i < items.length; ++i) {
             var item = items[i];   
    var m = item.synchronousMetadata;
    filenameToDesc(m, item.name.slice(0,-4));
    function filenameToDesc(metadata, Description) {
    var strTmpl = "name2Desc";
    var strUser = Folder.userData.absoluteURI;
    var filTmpl = new File(strUser + "/Adobe/XMP/Metadata Templates/" + strTmpl + ".xmp");
    var fResult = false;
    try
    { if (filTmpl.exists)
    filTmpl.remove();
    fResult = filTmpl.open("w");
    if (fResult) {
    filTmpl.writeln("<x:xmpmeta xmlns:x=\"adobe:ns:meta/\" x:xmptk=\"3.1.2-113\">");
    filTmpl.writeln(" <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">");
    filTmpl.writeln(" <rdf:Description rdf:about=\"\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\">");
    filTmpl.writeln("<dc:description>");
    filTmpl.writeln("<rdf:Alt>");
    filTmpl.writeln("<rdf:li xml:lang=\"x-default\">"+Description+"</rdf:li>");
    filTmpl.writeln("</rdf:Alt>");
    filTmpl.writeln("</dc:description>");
    filTmpl.writeln(" </rdf:Description>");
    filTmpl.writeln(" </rdf:RDF>");
    filTmpl.writeln("</x:xmpmeta>");
    fResult = filTmpl.close();
    metadata.applyMetadataTemplate(strTmpl, "replace");
    filTmpl.remove();
    catch(e)
    { fResult = false; }
    return fResult;

  • Get file name of an email attachment with sql query

    Hi all,
    How can I get the file name of an email attachment with a sql or pl/sql query?
    Thanks in advance.
    Edited by: JonasZzZz on Sep 14, 2009 10:52 AM

    Hi, anynone? please..

  • File name into text field

    Is there a way to display the forms file name, into a text field?
    Example: The form's file name is "MyForm.1.01.pdf"
    I would like to display "MyForm.1.01" in a text field on the form.
    If my form is saved and goes up a revision to say "MyForm.1.02"
    "MyForm.1.02" is then displayed in the text field.
    I was thinking, this could be on the pre open event, so that when the form is saved, it would display the new revision when the form is next opened?
    Thanks in advance.

    Hi,
    The following will get the file name:
    this.rawValue = event.target.documentFileName;
    I would put this in the docReady event, as this event fires only once, when the form opens.
    There is a sample here: https://acrobat.com/#d=ZnxO-dlXXFDS0GvYcQk2NQ
    Hope that helps,
    Niall
    Assure Dynamics

  • File name into document

    Is there a way to create a master doc page that automatically imports the current document file name into a desired location?

    Perhaps a text variable of the filename on the master? Look this up in the help.
    Mike

  • Method for quickly putting file names into IPTC core description?

    I would like to put the file names into the IPTC core description. The files are all named differently .Is there a way to batch this or any other way of automatically including it so that I don't have to do each file separately? Or perhaps there is a plug in?
    I am using PS5/ bridge on a mac.

    You only need a script… not a plug-in to do this. Search the bridge scripting forum as Im sure Paul has posted several variations of scripts that do this…

  • How to set attched file name while sending email through ABAP

    Hi All- tell me how to set attched file name while sending email through ABAP.
    regards...
    Abhay

    Sure,  when you are adding your entry to the packing list,  give the name in the obj_name field.
    *File 2
      mailbin = 'This is file 2'.
      append mailbin.
      data: start type i.
      data: end type i.
      start = tab_lines + 1.
      describe table mailbin lines end.
      mailpack-transf_bin = 'X'.
      mailpack-head_start = 1.
      mailpack-head_num = 1.
      mailpack-body_start = start.
      mailpack-body_num = end.
      mailpack-doc_type = 'TXT'.
      mailpack-obj_name = 'TEST2'.        "<-  RIGHT HERE
      mailpack-obj_descr = 'Subject'.
      mailpack-doc_size = tab_lines * 255.
      append mailpack.
    Regards,
    RIch Heilman

  • Copying file names from a folder into excel?

    I have a folder with over 200 files.
    I would like to copy the information/file names of these files into an excel spread sheet.
    I don't need to get all other extensions and information just the file names.
    Is there a way to do this?

    Open the folder,
    Select All,
    Copy,
    Open Excel and select a cell
    Paste.

Maybe you are looking for

  • 865PE NEO2-FI2R + games = not good

    I have a big problem with my new computer. The system is working like a charm in Windows applications and when I'm working with video editing, however I cannot play any games because of the major stutter I get in all games. I cannot seem to find a fi

  • Exported Interdemia Text Inedxed data from 8.1.7 to 8.1.6

    Hi all I get something interesting problem....I setup Intermedia Text on my DB1 running Oracle 8.1.6, index setup well and query works well. For some reason, I exported some Intermedia Text indexed data from aonther DB2 (8.1.7) and import to the one

  • Function Module for splitting(field) in CO02 t-code

    Function Module or enhancement for splitting(field) in CO02 t-code Need function module for inserting a value in field(Max No of splits) in Transaction CO02 Message was edited by:         Mohan Kumar

  • Airport Update question

    I have Airport ver. 9.52 on my iBook. When I check for updates it says that there is an update available called: *Airport Extreme Driver Update 2005-001* (Version 1.0) +"This update resolves AirPort compatibility issues with certain third party 802.1

  • Units (a units conversion program)

    I noticed that this super-useful little command line units conversion program wasn't in the repositories so I made a PKGBUILD for it: # $Id: PKGBUILD,v 1.12 2003/11/06 08:26:13 dorphell Exp $ # Maintainer: # Contributor: Stenico pkgname=units pkgver=