Apple script texedit


Question is: How can I talk text edit app to take five first (seven, etc) words in the document and place it in another file? and any other words with specified numbers, EQ words of 4 to 8 in this text?

Thank you

The following script assumes that you already have a document open in TextEdit. It will prompt you for all of the words you want to extract in another document. This prompt looks like this to select the first ten words. You can also specify 4.9, or of a different range in the number of words in the document.

Copy and paste the following in your Script Editor AppleScript (launchpad: others: Script Editor). Click on the hammer to the compilation and the adjacent button icon to run it. You must save this twice. First of all, as the source of the AppleScript by selecting the file menu: Save... File format: text. This will add the extension of applescript to your script source. Press the option key and then file menu: Save under... and your file Format can be scpt, scptd or application. Put this one on your desk and quit the Script Editor.


-take the user input range n, n word and remove it from the current

-TextEdit document into a new document on the desktop.

game of aDoc to ((path to the Office) as text) & "wordselection.txt".

wordSel the value of text returned of (display dialog response 'Enter the word interval to n, n' by default ' ")

-Separate the numbers in a list

the value {oldTID, my text item delimiters} to {my point of text delimiters, ","}

the value word_values to (text elements of wordSel)

the value Separators to oldTID AppleScript point text

say application "TextEdit".


say text of front document

define allwords to count words of her

if ((second element of word_values) as integer) > allwords then

Display alert "You specified more words that are in the document." give up after 10


end if

Define myWords in words ((first element of word_values) as whole) thru ((second element of word_values) as whole)

end say

end say

say application 'Finder '.


set fileRef to (open for access file CODA with writing permission)

-Separate words by spaces

the value {oldTID, my text item delimiters} to {my point text delimiters, space}

write ((myWords comme texte) & back) to fileRef starting at eof

the value Separators to oldTID AppleScript point text

FileRef close access

on error


FileRef close access

end try

end try

end say


Tags: Mac OS & System Software

Similar Questions

  • Apple Script Question

    I am learning Apple Script and I came across a roadblock. I was playing around with "get position and it does not work."

    The script is: tell application "Finder" to get the position of Finder window 1.

    It compiles OK but when I run it I get this error: error "Finder has been an error: cannot get the window id position Finder 661 ' number 1728 from the position of the Finder window id 661.

    My latest version of Mac OS is 10.11.5.

    The script editor version is 2.8.1.

    Also I use Apple Training Series: Applescript 1-2-3.

    Thanks for any help.

    Replace postion by position.


  • Apple script to check the part of iTunes library XML with another application.

    Y at - there no apple for script

    Set 'share the XML library with other applications iTunes'. under the name selected

    • iTunes
    • Preferences
    • Advanced tab...

    I want to read itunes Media Library .xml, but in the last version of iTunes without xml is created by default,

    so I want this XML created by my application through the apple script.


    I don't think you can change that setting via AppleScript, however once you have enabled then the XML file will be generated and updated every time that the library is updated.


  • Apple script to check the part of iTunes XML library with other applications.

    Y at - there no apple for script

    Check "Sharing iTunes library XML with other applications." Of

    • iTunes
    • Preferences
    • Advanced tab...

    I want to read itunes Media Library .xml but lates itunes no xml is created by default,

    so I want this XML created by my application through the apple script.

    iTunes12.4 - new with the parameter preferably 12.2 iTunes to turn create .xml

    If you really want an AppleScript, I think you should ask on the iTunes for Mac forum, or maybe the OSX Technologies.

  • Apple Script to apply rules in

    • I've created some rules in my to change the background color of specific messages
    • And I also created rules in the mail server in order to move the messages to a folder

    For messages in the Inbox folder, everything is fine.

    But if the message has been moved by the server rule in another folder, then rules the do not apply (and reasons twisted, this is normal: & viewlocale = en_US).

    Then if I apply the rules manually by pressing Command + Option + L < code > < code >, rules will apply as they should.

    I want to automate this action. Is it possible with Apple Script? Can you help me with this? The steps would include, I guess that:

    1. Choose the smart folder "today."
    2. Select all messages in this folder;
    3. Perform the action "Rules" for selection.

    < pre >

    using terms from application "Mail".

    Tell application "Mail".

    the value of the message_count in HOW-TO-GET-MESSAGES-FOR-TODAY-SMARTBOX County

    Repeat with i from 1 to the message_count

    the value this_message to article i of MESSAGES TODAY ' HUI-SMARTBOX

    say this_message

    -That's something like the RULES APPLY

    tell the end

    end repeat

    tell the end

    end using terms from

    < / pre >

    If it is not possible for a smart folder, then I want to do, it goes all messages in all mailboxes mailbox (or with messages in the specific mailbox).

    Apparently, this is not possible as long as such action is not be scriptable.

  • Network advertising readers and apple script editor or

    I have a new laptop Mac. I have it on a Windows domain and I get my drive mapping in the sidebar when I connect with my AD account. When I change my account to a mobile account, I lose the map in the sidebar. I get it if I connect to the server, but does anyone know how I can get there?

    I did some research and I thought of making an Apple Script would be the way to go. I'm a total newbie when it comes to the Script Editor, but I managed to do work properly when I have a connection of network here at work. But if I bring home, of course I'll get an error. Here is where I'm stuck. I need help to create a "if exists" so if a user is at home when he's trying to turn up the volume it will not give an error message when it fails.

    Here's what I have so far. When I press the hammer icon it is not an error, but when I press the play button it give me a 'walk', but disappears as soon as he says.

    Tell application "Finder".

    If there is "smb://abc/EmployeesHome" then

    turn up the volume 'smb://abc/EmployessHome' as username "username".

    other (* Nothing *)

    end if

    tell the end

    Any help would be appreciated!

    You should check the thing, as for example address public IP of the computer to determine which network it is. Methods of doing this include:

    the script "curl"shell


  • Open ssh server files automatically with apple script

    Hello from respected people

    I am trying to build an apple script first terminal connection open ssh with details and after connecting, it will open a python script which is on ssh server automatically. I want to do all these tasks in a script unique apple. I already tried to build automatic ssh connection and I did. but I am facing problem, how can I call a python script in ssh server automatically.

    as if I had a python files in ssh server /home/exe/

    so I want whenever I run Apple script it connect in ssh and opens automatically.

    I'm new in the apple script please help

    I tried it here 3 days but no luck, please help me

    At first glance, it seems to me that you need to refresh your ssh.

    # ssh python /home/exe/

    will ssh to the specified host and run the command "python /home/exe/".

    To run this via AppleScript, put it in a shell script command:

    the shell script "ssh python /home/exe/

  • How to disable the "Swatch overprint [Black] to 100%" option in Indesign by Apple script

    Hi friends,

    I'm new to Indesign Scripting with Apple Script. As a beginner, I'm doing some basic scripting in Indesign by Apple Script.

    My goal is to turn off the "Swatch overprint [Black] to 100%" option in Indesign. This option is available when we go to Indesign-> Preferences-> appearance of black.

    In addition, if a user opens a file, in which the sample is already activated, then he should encourage him to turn off.

    I can do a display dialog box in AppleScript. But I am little unsure as how can I go ahead and disable this option. I tried this script below:

    say application «Adobe InDesign CS4»

    say each window layout to the value the overprint preview to fake

    end say

    However, it changes the display of the overprint preview option.

    Appreciate your help and suggestions!

    Thank you


    say application "Adobe InDesign CS5.

    say the active document

    set overprint black of the document preferences to false

    end say

    end say

  • Remove the attribute by the Apple script


    All, I'm new to Indesign Scripting, and I hope that someone can help me with the following attribute problem.

    Can someone write / suggest me how can I remove the xml attribute. By Apple/Java Script

    Example 1 = >

    I want to remove the attribute (its manual I)

    Any idea is appreciated!

    It isn't here either but whatever.

  • Apple script apply prefix the number in a particular order?

    Hi all

    I would like to write a script that adds a prefix number to a bunch of files in a very particular order.

    Please see screenshot below.

    I want to precede the files shown on the left, starting at '001' but in the order of the list on the right.

    That is to say

    001 clubworx BA CYF

    002 name me BASS


    I have

    Any help with this is greatly appreciated.

    Thank you for taking the time to read this.

    Kind regards


    Use the following syntax:

    Set namelist to {'BA clubworx CYF.fxp', 'name me Bass_2.fxp"}

    the_num Set to 0

    Repeat with this_item in namelist

    Set the_num to the_num + 1

    the_string value «»

    If the_num < 10 then set the_string to '0' & the_string

    If the_num < 100 then set the_string to '0' & the_string

    the value the_string the_string & the_num & "" & this_item

    Tell application "Finder".

    Set the name of the file window this_item the_string 1

    tell the end

    end repeat


  • Why the apple script works in indesign CS3?

    I made a square, entered in the window > automation > scripts. I clicked on the brand script culture, nothing. Then I read a few threads and seemed more think that if you try javascript that will work, but it didn't for me. I'm in CS3. If anyone can help, I'd appreciate it.

    Stick the 3 lines directly under the line

    Tell application "Adobe InDesign CS3"


  • How to get the files in the subfolder by Apple Script

    say application 'Finder '.

    the value ArtFolder to choose a folder with guest "Select the folder of Art: - > >".

    set ChapNameFolders to the folder list ArtFolder without invisible

    Repeat with ChapFolder in ChapNameFolders

    set ArtFiles for files in ChapFolder

    display the dialog ( )County ArtFiles( )

    Repeat with ArtFileItem in ArtFiles

    value FileInfo info for ArtFileItem

    set File name to the of ArtFileItem name

    if folder of FileInfo is true then

    view the dialog box FileName as string

    end if

    end Repeat

    end Repeat

    end say


    I used code above to get the files in the subfolder, but it does not, it will fail in second REPEAT & do not get the files in the subfolder...

    Can someone help me solve this problem...

    Thank you.

    My problem has been resolved by this code: -.

    say application 'Finder '.

    the value ArtFolder to choose a folder with prompt "select Art Folder :---> >.

    Repeat with ChapFolder in (get each folder from the folder ArtFolder)

    Repeat with ArtFile in (get each file from the folder ( as aliasChapFolder))

    display the dialog box ArtFile string

    end Repeat

    end Repeat

    end say

    Thank you...

  • I have an apple quarkXpress script I want to convert to InDesign

    I have an apple quarkXpress script I want to convert to InDesign. We really think hard on the conversion on InDesign, but one problem is that I have an apple script that automates much of the work. I don't know even if you can use applescript with InDesign. The script we use shaped text with style sheets and incorporates images in the text.  Any help would be greatly appreciated. Thank you

    InDesign supports applescripting. Why not ask your question in the InDesign Scripting forum?

  • script java script Apple...

    Hello world

    As I want to change the script apple java script code below. I tried to reproduce the frames with java script and its working fine. But I don't know how to use that State in javascript. If it is possible to which the State of java script, so I don't want to go to the loop. Can someone look into this and help out me.

    -Apple script-

    Set {} xx
    Tell application "Adobe InDesign CS3"
    tell document 1
    Repeat with i from 1 to (text block count)
    If the parent of the parent of the text frame class I is not master then spread
    fine adjustment of xx ID of the text block I have
    end if
    end repeat
    duplicate (each text frame whose id is xx)
    Delete (each text frame whose id is xx)
    tell the end
    tell the end

    -Java script-

    var doc = app.activeDocument;

    var myFrames = doc.textFrames.everyItem ();

    myFrames.duplicate ();


    Thanks in advance


    JavaScript is not an equivalent to which clause of AppleScript. If your script JS version might look like this:

    myDoc var = app.activeDocument;
    var myFrames is myDoc.textFrames.everyItem () .getElements ();.
    var XX = [];
    for (i = 0; i< myframes.length;="" i++)="">
    var myFrame = myFrames [i];
    If (! = "MasterSpread") {}
    XX.push (myFrame.ID);

    for (j = myFrames.length - 1; j > = 0; j-) {}
    myFrame = myFrames [j];
    If (IsInArray (, xx)) {}
    var myDup = myFrame.duplicate ();
    myFrame.remove ();

    function IsInArray (myString, myArray) {}
    for (x in myArray) {}
    If (myString is {myArray [x])}
    Returns true;
    Returns false;

  • [Script] How the auto respond to an address specified when receiving any mail

    I need to send an email with the text previously set to exactly 1 address but I need it to be sent to every mail I receive, except those that are sent from an address.

    For example, any email me, with the exception of the ' [email protected]', I would answer "admin@mydomain" with the response of multi doublet with paragraphs of:

    "You lucky dog.

    Someone has sent you the just

    I think someone like you.

    Don't let your wife know.

    I tried to set up a mail rule, but mail only allows me to reply to the sender. It gives me the opportunity to call a script but I can't make an Apple script in Automator. Whatever I do in here, Mail can not see it.

    I managed to write send an Automator application which opens the message in Mail for me when I double click on it and then I just need to hit, but the whole point is that I want not automated. If I get an email from [email protected] then I want to admin@mydomain to receive an e-mail to tell him that he is loved by someone and I want all this to happen automatically.

    So basically what I need is an Apple Script which includes a static message and sends it to a static address, so I can tell Mail to use as the action when he receives an e-mail. Unfortunately, as far as I know about AppleScript is 'say Mail' and 'end tell '...

    Can someone help me, please?

    You can watch it too deeply. You won't answer at all – looks like you want to open a new message coming out when a new coming. It is not serious what who is, or who he came (with the exception of yourself).

    So, here's an example - it checks the incoming message for make sure there is at least a message that is not your own address. Is there then it creates a new message and sends it.

    Use AppleScript version "2.4" - Yosemite (10.10) or later version

    Use Scripting additions

    property myAddress: "[email protected]."

    property myMessageBody: "you lucky dog.

    Someone has sent you the just

    I think someone like you.

    Don't let your wife know.

    terms of application "Mail".

    we messageList perform the action of mail with messages in the mailbox mbox for rule agouverner

    -make a new message

    say application "Mail".

    game of newMessage to (make new outgoing message with properties {subject: "new mail", content: myMessageBody})

    tell newMessage

    do the new to recipient with properties {"address:"[email protected]""}

    end say

    Send newMessage

    end say

    end perform the action of mail with messages

    end terms of

    It is written as a mail rule, so add it to your ~/Library/Application Scripts/ directory, and then configuration a rule in to run this script for incoming mail.

    You implement audit "not post me" in the rules dialog box (for example only call the script when the sender is not yourself).

Maybe you are looking for

  • Outdated Safari browser?

    I'm currently under Safari 9.1.2, yet many sites Web I visit tell me that my browser is out of date and I need to install the latest version. Most of the time, I just 'ok' it and continue, but some places it seems a problem. Anyone else had this prob

  • Tablet AT100 freezes sometimes

    After that I tried to connect my tablet with an external hard drive (cable withoutelectric), it has been frozen.So, I have to restart with the power button. After that it worked well. But a few days later the problem came back. Now it freezes several

  • CD/DVD ROM IO error - please help

    Hi all I've just adapted to a new TEAC DW-224th on my TECRA S1 because the former was damaged (it has been detected, but its mechanics did not work at all after an access to an airport). This is detected by the operating system (Win XP) and mechanica

  • How to interpret the orbit and Point of reference Timebaseplot

    Hello the plot of the orbit and the time base includes a "red dot" called the reference point. I really didn't understand this meaning. Please, take a look at the photo "orbit_timbase_plot. PNG ". Thanks a lot for your help!

  • How to extract a part of the image to another image of lager?

    Hello. Please download the images named ' 333 - 1.png "and"333.png"of the spare part. I want to extract the image named "333 - 1.png" of the image named "333.png" automatically. But how can I do? I hope you can help me. Thank you. melo_xu