Creatiing new document in TextEdit and saving it to a folder

I'm just starting with applescript. I would like to write a script that will open an e-mail, copy the contents to a new TextEdit or TexShop file, and save the new document to a particular folder. Ultimately the name of the new document should depend on the content of the e-mail, but for now I'd be happy to just be able to create a new TextEdit document and save it in a specified location with a specified name.
I've tried a couple of things, including
tell application "TextEdit"
activate
make new document
set fileSpec to "Disk:Documents:Barbara:TestFile"
save document 1 in fileSpec
end tell
which creates a new untitled document and brings up a dialog, which isn't what I want. I also tried something that involved "with properties {name:TestFile} but that didn't work either.
I have Applescript the definitive guide and Applescript in a Nutshell but neither seems to describe this situation, although surely it's a common one.
I'd be most grateful for any help.
macbook   Mac OS X (10.4.6)  

Not all Macintosh e-Mail'er applications are scripted the same; thus, Apple's 'Mail' e-Mail'er application is assumed.
-- Create dynamic path to the desired folder.
tell application "Finder" to set dFolder to ((startup disk) as string) & "Documents:Barbara:"
tell application "Mail" -- Utilize 'Mail's AppleScript dictionary.
set selected_Messages to selection -- Obtain a list of selected e-Mail messages.
repeat with i in selected_Messages -- Cycle through the selected e-Mail messages.
set tSubject to my Clean_String((subject of i) as string) -- Obtain each e-Mail message's 'Subject' line.
set tContent to (content of i) as string -- Obtain each e-Mail message's contents.
set fRef to open for access file (dFolder & tSubject) with write permission -- Create a new file at dFolder.
write tContent to fRef -- Write the e-Mail message to the new file.
close access fRef -- Close the new file.
end repeat
end tell
on CleanString(localString) -- 'Macintosh file names cannot contain a ':'. Here it is replaced by '_'.
if (local_String contains ":") then -- Check for presence of ':" in local_String
-- Standard 'AppleScript's text item delimiters' preparation.
set {oAStid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ":"}
set local_String to text items of local_String -- Creates a list of items separated by ":'.
set AppleScript's text item delimiters to "_" -- Set a new delimiter character.
set local_String to local_String as string -- Creates a string from created list with '_' as the new delimiter.
set AppleScript's text item delimiters to oAStid -- Restore 'AppleScript's text item delimiters'.
end if
return local_String -- Return modified / non-modified string.
end Clean_String
The created generic text file can be viewed and edited with any text editor.
Also, the 'repeat ... end repeat' portion can be rewritten as ...
repeat with i in selected_Messages -- Cycle through the selected e-Mail messages.
set fRef to open for access file (dFolder & (my Clean_String((subject of i) as string))) with write permission -- Create a new file at dFolder.
write ((content of i) as string) to fRef -- Write the e-Mail message to the new file.
close access fRef -- Close the new file.
end repeatf
  Mac OS X (10.4.4)  

Similar Messages

  • I have typed many documents to pages and saved as a folder i have just looked in the folder and everything has gone help

    i have typed many documents on pages and saved to a new folder i created i have just opened it half hour ago and saved some more and all ok i just reopened to save another and all the documents have gone help how do i get them back and where they go ??????

    On Lion 10.7.x you need to hold the CMD+r Keys insyead of notting from an Instsall Disc, but try that & step 3 onward...
    "Try Disk Utility
       1. Insert the Mac OS X Install disc, then restart the computer while holding the C key.
       2. When your computer finishes starting up from the disc, choose Disk Utility from the Installer menu. (In Mac OS X 10.4 or later, you must select your language first.)
          Important: Do not click Continue in the first screen of the Installer. If you do, you must restart from the disc again to access Disk Utility.
       3. Click the First Aid tab.
       4. Click the disclosure triangle to the left of the hard drive icon to display the names of your hard disk volumes and partitions.
       5. Select your Mac OS X volume.
       6. Click Repair Disk, (not Repair Permissions). Disk Utility checks and repairs the disk."
    http://docs.info.apple.com/article.html?artnum=106214

  • When working on document in numbers and saving it I then try to open on iPad. It is not syncing what do I have to do after using on Mac to then be able to upload on iPad.  I have set cloud up and it works with keynote

    When working on document in numbers and saving it I then try to open on iPad. It is not syncing what do I have to do after using on Mac to then be able to upload on iPad.  I have set cloud up and it works with keynote

    Welcome to the Apple Community.
    I have seen previous versions mentioned in a pop up message before on iCloud.com, but I'm not really sure at all how it would help, as I couldn't get it to do anything.
    The best advice I have at this time is to back up your work on your iOS device by regularly saving it to iTunes, if anything goes wrong you can then either load it into the numbers app again on the device or recover it via iTunes on your computer.
    My syncs are immediate, I never get chance to see if it works in the background, sorry.

  • When i open a new document, my "width" and "lenght" add two zeros automatically to file size??? For example basic A4 size in mm is 210 00mm x 297 00mm? And i can´t do nothing about it! Why on earth?

    When i open a new document, my "width" and "lenght" add two zeros automatically to file size??? For example basic A4 size in mm is 210 00mm x 297 00mm? And i can´t do nothing about it! Why on earth?
    This "error note" must have something to do about it?

    elppaelo,
    You may try the list.
    The following is a general list of things you may try when the issue is not in a specific file (you may have tried/done some of them already); 1) and 2) are the easy ones for temporary strangenesses, and 3) and 4) are specifically aimed at possibly corrupt preferences); 5) is a list in itself, and 6) is the last resort.
    If possible/applicable, you should save curent artwork first, of course.
    1) Close down Illy and open again;
    2) Restart the computer (you may do that up to 3 times);
    3) Close down Illy and press Ctrl+Alt+Shift/Cmd+Option+Shift during startup (easy but irreversible);
    4) Move the folder (follow the link with that name) with Illy closed (more tedious but also more thorough and reversible);
    5) Look through and try out the relevant among the Other options (follow the link with that name, Item 7) is a list of usual suspects among other applications that may disturb and confuse Illy, Item 15) applies to CC, CS6, and maybe CS5);
    Even more seriously, you may:
    6) Uninstall, run the Cleaner Tool (if you have CS3/CS4/CS5/CS6/CC), and reinstall.
    http://www.adobe.com/support/contact/cscleanertool.html

  • I modify a document en word and saved it. I need to return to the document before the modification. How can I do it? Thank You

    I modify a document en word and saved it. I need to return to the document before the modification. How can I do it? Thank You

    Are you using Time Machine? If not, do you have a backup?
    Best of luck.

  • Creating a new document with columns and printing effects

    If you create a new document and set columns into it in the new document menu, and then subsequently create images, tables, text etc. in the document that are bigger than one column (that stretch for example across the entire page), will the part of the image that's in the gutter print and/or show up if it's saved as a PDF?
    Help!
    Thanks!

    Guides are only there as a reference for you to help in alignment.They don't restrict what or where objects can be placed or affect their visibility or printability.
    To see what your page will look like in print, switch to Preview Mode (fast way is to press W with nothing selected).

  • I synced with new computer, lost apps. reinstalled but Office HD docs that we're not lost when I reinstalled will not cut and paste. Will I need to use only new documents to cut and paste?

    I synced my IPad2 with a new computer and lost all apps. I reinstalled apps. When I reinstalled the Office2HD, all documents were still ther, but I am trying to cut and paste one and it is not allowing? Will I need to save new documents there for this function to work?

    There are dozens of possibilities, Lisa.
    Which C50-A do you have? There is a label on the bottom.
    What security applications do you have installed? Webroot is a common offender.
    Do you have Microsoft Office installed? If so, which version?
    Do you use Bluetooth?
    Did you upgrade to Windows 8.1 properly, following carefully the instructions here?
       How to Update from Windows 8 to Windows 8.1
    Find a situation that always gives you trouble, so that know when we learn something.
    Then see if that trouble occurs after a clean boot.
       1. Open the System Configuration utility (msconfig.exe). You can do that by typing msconfig at the Start screen and pressing Enter.
       2. On the Services tab, set the Hide all Microsoft services check box and then click Disable all.
       3. On the Startup tab, click Open Task Manager, right-click and disable each Startup item. Then close Task Manager.
       4. Back on the System Configuration screen, click OK, and restart the computer.
    -Jerry

  • New documents:  Configure SSL and Integrate Oracle Reports

    All,
    Be sure to check out these new documents from Oracle Support on the Oracle9iAS Portal Center.
    Support page:
    http://portalstudio.oracle.com/servlet/page?_pageid=1787&_dad=ops&_schema=OPSTUDIO
    1. Configure Oracle9iAS Portal to use SSL with Global Server Certificates. Global Server Certificates are the standard
    with Verisign and BT Trustwise. By following this Oracle Metalink document, you can enable ALL browsers to use 128-bit
    encryption (including old Export browsers) when accessing Oracle9iAS Portal.
    2. Integrate Oracle Reports and Oracle9iAS Portal. Learn how to display drill down reports from Oracle Reports Builder
    as portlets within Oracle9iAS Portal using this step by step Oracle Metalink document.
    Support page:
    http://portalstudio.oracle.com/servlet/page?_pageid=1787&_dad=ops&_schema=OPSTUDIO
    Alos, find more information about related documents, patches, upgrades and other Metalink information on the Support page on Portal
    Center.
    Portal Center
    http://portalcenter.oracle.com
    Sue

    All,
    Be sure to check out these new documents from Oracle Support on the Oracle9iAS Portal Center.
    Support page:
    http://portalstudio.oracle.com/servlet/page?_pageid=1787&_dad=ops&_schema=OPSTUDIO
    1. Configure Oracle9iAS Portal to use SSL with Global Server Certificates. Global Server Certificates are the standard
    with Verisign and BT Trustwise. By following this Oracle Metalink document, you can enable ALL browsers to use 128-bit
    encryption (including old Export browsers) when accessing Oracle9iAS Portal.
    2. Integrate Oracle Reports and Oracle9iAS Portal. Learn how to display drill down reports from Oracle Reports Builder
    as portlets within Oracle9iAS Portal using this step by step Oracle Metalink document.
    Support page:
    http://portalstudio.oracle.com/servlet/page?_pageid=1787&_dad=ops&_schema=OPSTUDIO
    Alos, find more information about related documents, patches, upgrades and other Metalink information on the Support page on Portal
    Center.
    Portal Center
    http://portalcenter.oracle.com
    Sue

  • I am trying to use the liquify tool for the first time. I created a new document (RGB/8) and before I place my photo, the liquify option is available. After I place the photo, the liquify option disappears. What am I doing wrong?

    I am trying to use the liquify tool for the first time. I created a new document (RGB/8). Before I place my photo, the liquify option is available. After I place the photo, the liquify option disappears. What am I doing wrong?

    What am I doing wrong?
    For one thing you forgot to mention the version of Photoshop you use.
    Did you place the image as a Smart Object? Liquify got Smart-capabilities with Photoshop CC.

  • Missing recent documents in TextEdit/Preview - File

    This issue happened after merging a new Tiger OS with an encrypted home directory (File Vault). I can see my recent docs and apps if I switch them on within the System Preferences. Other apps like BBEdit or Microsoft Excel for example are tracking my recent docs also correctly. But the menu recent documents in the applications TextEdit and Preview remain empty independet how many docs I open and save. I therefore tried another user with the same OS without File Vault and everything behaves like normal. If I make a new document within TextEdit and do save it I can see it in the menu File as recently opened documents. Does anybody have an idea? Please HELP!
    Mac Pro   Mac OS X (10.4.8)   5GB RAM

    The recent documents lists for TextEdit and Preview are contained within their respective preferences files. Try deleting these files and see if that solves the problem:
    ~/Library/Preferences/com.apple.TextEdit.plist
    ~/Library/Preferences/com.apple.Preview.plist
    (Where the "~/" is your home directory.)

  • Trying to save a new document and then "The file "lyrics project.pages-tef" couldn't be opened."

    As the title says...  Open Pages, Create new document, click Save, the dialog box comes up, I give it a name and select the Desktop as the destination, click OK, the dialog box disappears for about a second and then I get the above message.
    No way to save the doc.  I even copied the text, opened another new document, Renamed it and tried to save and same results.  It's a very simple document saved in Pages format, without involving iCloud so it should be as easy as it gets.  On top of that, I just want to Save.  Why is it trying to Open something???
    I ended up having to copy the text into an email and sending it to myself in order to copy it into a SimpleText file.
    Any ideas on what might have been going wrong?
    MacBook Pro 13, OSX 10.8.2, current version of Pages.
    Thanks much.
    Bo

    That is the iCloud version of the document as I understand it. There is a version saved on the Net for iCloud to be shared and a local version on your hard drive. One of those is currently inaccessible.
    http://www.macworld.com/article/1163173/bugs_and_fixes_losing_iwork_documents_in _icloud.html
    Peter

  • Photoshop cc can't open and make new documents.

    I'm using adobe creative cloud and photoshop cc.
    When I run the Photoshop cc, it can't open and create new documents.
    Open and make new documents Photoshop don't work so i terminate a photoshop cc use windows task manager.
    I use windows7 ultimate k on lenovo x220t.
    I uninstall the Photoshop cc and install again but symptoms refeat.
    Please give me good opinion.

    You have permissions issues with your user folder and the location where the PS swap files are stored. You need to fix that part...
    File Permissions Stuff
    Mylenium

  • Cannot open documents originally in Word 2008 for Mac and saved in Pages 09

    I have both Word 2008 for Mac and IWork 09. Working on long and complicated documents in Word, I had a number of problems with Word so that I decided to switch to Pages. I copied my documents into Pages, and saved them in Pages. Now, when I want to open them in Pages, I get a message that Pages cannot open those documents.The message says: the "file" couldn't be opened. The required index.xml file is missing.
    Again: original Word document, properly saved into Pages. the saved Pages file cannot be opened in Pages.
    What do I do wrong?
    Thanks.

    You haven't done nything. This problem has happened for people from time to time
    Read some threads
    [http://discussions.apple.com/thread.jspa?messageID=10050371]
    [http://discussions.apple.com/thread.jspa?messageID=10509885]
    [http://discussions.apple.com/thread.jspa?messageID=9514639]
    [http://discussions.apple.com/thread.jspa?messageID=9401344]
    There are more if you do your on search in the forum.
    Try to save open and save the Word doc again in Pages. It might work better.

  • When I open a new document and press letter key to type i get no response. I can't figure why.

    When I open a new document in Pages and pressa a letter key to type, I get no response. I can't figure why.
    I also have Mail open on my dock, but when I double click it does not open mail and when I try to quit from dock or from toolbar, it doesn't close.  What's up?

    You could choose to open a word processing document instead of the page layout one, in the New template chooser.

  • Send as email attachment the billing document as pdf when created and saved

    HI All,
    I have already searched the forum but could not find  a satisfying answer so i am posting this question,
    The requirement is to send an email containing biiling document converted to pdf format when a billing document
    is created and saved in VF01 transaction.
    I have already converted the output to pdf format in my driver program and also know how to send an email containing the same ..but this works only when user prints using VF31 .
    Kindly tell the configuration steps which are required...and hot to achieve the same.
    Regards,
    Prateek

    Hi Prateek,
    There is a blog on a similar topic which explains how to email purchase order in SAP to the vendor. The settings are required in Vendor Master, NACE and SCOT.
    Following is the link to it.
    http://architectsap.com/blog/sap/sap-mm-purchasing-send-purchase-order-by-mail-to-vendor-in-sap/
    It has given steps to trigger the output.
    Its not exactly what you require, but might be helpful.
    Regards,
    Abhijeet Kapgate

Maybe you are looking for