AppleScript to delete the whole line if ..

Im using the following code to find and replace with "target word" but I would like to DELETE the whole line instead of replacing the actual word.
so it would be
if the line contains www.network -> Delete the whole line.
Thanks in advance!
set theTargetWords to {"www.network"}
tell application "Pages" to activate
tell application "System Events" to tell process "Pages"
  -- Open the "Find & Replace" window:
  keystroke "f" using command down
          repeat until exists window "Find & Replace"
          end repeat
          tell tab group 1 of window "Find & Replace"
  -- Adjust the settings:
  click radio button 2 -- Advanced
                    if value of checkbox 2 is 1 then click checkbox 2 -- Don't match case
                    if value of checkbox 3 is 1 then click checkbox 3 -- Whole words
                    if value of checkbox 1 is 0 then click checkbox 1 -- Search previous text (loop)
  click pop up button 1 -- find in
  click menu item 1 of menu 1 of pop up button 1 -- Entire document
  click pop up button 2 -- replace style
  click menu item 1 of menu 1 of pop up button 2 -- Any
  -- Delete every target word:
                    set value of text area 1 of scroll area 2 to ""
                    repeat with thisWord in theTargetWords
                              set value of text area 1 of scroll area 1 to thisWord -- the target word
                              click button "Replace All"
                    end repeat
          end tell
end tell

if you want to script an application, read and use the application scripting dictionary. using System Events to script the GUI is something you should only do as a last resort. It creates clunky, slow, overly complex, and breakable scripts.
try this to start:
tell application "Pages"
          delete (every paragraph of body text of document 1 whose contents contains "some key phrase")
end tell

Similar Messages

  • Xcode - delete the whole line shortcut missing

    Hi,
    Is there any way to have a shortcut to delete the line? you know, like D from Vi, or CMD+D from Eclipse, o CTRL+D from JEdit, or ... you got it.
    please tell me I'm blind and there is a shortcut for that.
    just for the record, there is a shortcut option to SELECT LINE, so why not one for DELETE LINE ?
    please help,
    Thanks,

    Hi Grimmac
    Many of the applications that Apple themselves make include a sub-set of commands from the emacs editor. Xcode is no exception to this. One of the useful commands from emacs is control-K (or ^K). The first press deletes from the cursor to the end of the line, the second press deletes the carriage return and brings up the next line. Subsequent presses repeat this sequence of events.
    Other useful commands are ^A and ^E to move to the start/end of a line, so to delete a complete line from the beginning you can use ^A^K^K.
    What makes these commands really worth knowing is that you can use them in Safari to edit URLs, or in Terminal to edit Unix commands, and in many other Apple made applications.
    If you do a Google search for "emacs" then you can quickly find the full list of commands. Xcode only supports a few of them, mainly the control + single key ones.
    You can also make your own personal keyboard shortcuts from the Xcode Preferences menu option.
    Bob

  • TS2755 When I click on a  IPhone number in contacts to send a message.  It keeps trying to send the message to the land line.  I deleted the whole contact and re-entered it.  But, still wants to send to the land line instead of the IPhone.

    When I try to send messages to another IPhone.
    I go to contacts.
    Touch IPhone number.
    Type message.
    Hit send.
    Comes back to me.
    "Can not send messages to land line"
    Well I did not touch the land line number - I touched the IPhone number.
    I have deleted the whole contact, and re-entered it. 
    I have turned the IPhone off and on.
    Still I get this message on only two of my contacts.
    HELP

    I can't delete my question, so I'll just say that you press on the type of number written in the box to the left of the box you typye the number into.  Dumb or what? 

  • While typing in an email, I can not delete or backspace a single letter. When I delete one letter, the whole line disappear.

    While typing in an email, I can not delete or backspace a single letter. When I delete one letter, the whole line disappear. I am using Window 7 and latest Firefox.
    == This happened ==
    Every time Firefox opened
    == Using Firefox on my new machine with Window 7.

    Start Firefox in [[Safe Mode]] to check if one of your add-ons is causing your problem (switch to the DEFAULT theme: Tools > Add-ons > Themes).
    See [[Troubleshooting extensions and themes]] and [[Troubleshooting plugins]]
    If it does work in Safe-mode then disable all your extensions and then try to find which is causing it by enabling one at a time until the problem reappears.
    You can use "Disable all add-ons" on the [[Safe mode]] start window to disable all extensions.
    You have to close and restart Firefox after each change via "File > Exit" (Mac: "Firefox > Quit"; Linux: "File > Quit")

  • How to delete a whole line in cmd prompt in Linux

    Hi all,
    How to delete a whole line in cmd prompt in Linux using short key?
    ex: [oracle@host1 ~]$ cd /u01/app/oracle/product/11.2.0/dbhome_1/
    Thanks

    yes ctrl+ak or ctrl+eu both are better. if you look from that perspective, go end and delete will be the same job too. (ctrl+eu) (but for me in such a command line, for example cding in to the directories ,the cursor will be at the end of the line %99 of the time :) )
    about ctrl-t,
    Drag the character before the cursor forward over the character at the cursor, moving the cursor forward as well. If the insertion point is at the end of the line, then this transposes the last two characters of the line.
    for ex:
    misspelled command date -> daet -> ctrl+t -> date
    or
    misspelled command $APPPL_TO -> place the cursor on third P press ctrl+t repeateadly till the P will come to the end -> APPL_TOP

  • I tried to delete one item from an email folder, and my computer deleted the whole file. I cant fint it anywhere.

    I tried to delete one item from an email folder, my computer deleted the whole file and I cant find it anywhere. Any ideas?

    lindafromgainesville wrote:
    ...is there a seperate trash for email?
    In Mail, yes -

  • How to delete the logical lines in JTextArea

    Hi all,
    Now that I know how to find the logical line count in JTextArea as
    I found the following in the forum.
    public static int getLineCount (JTextArea _textArea)
    boolean lineWrapHolder = _textArea.getLineWrap();
    _textArea.setLineWrap(false);
    double height = _textArea.getPreferredSize().getHeight();
    _textArea.setLineWrap(lineWrapHolder);
    double rowSize = height/_textArea.getLineCount();
    return (int) (_textArea.getPreferredSize().getHeight() / rowSize);
    I want to delete the 4th line to the last line and append ... at the 4th, if the getLineCount exceeds 3. Does any body know how to do so?
    The intention is for the multiline tooltip as I just want to show
    the first three logical line and ... if the string is too long.
    Thanks
    Pin

    The code looks good to me. The only thought I have is that the y coordinate for the rowThree point is wrong and is referencing row four.
    I've been playing around with using a JTextArea as a renderer for a JTable. I have it working so that "..." appear when the text exceeds 2 rows. Try clicking on "B" in the letter column and then the update cell button a few times to add text. My code is slightly different than yours.
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class TestTable extends JFrame
         private final static String LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
         JTable table;
         Vector row;
         public TestTable()
              Object[][] data = { {"1", "A"}, {"2", "B"}, {"3", "C"} };
              String[] columnNames = {"Number","Letter"};
              DefaultTableModel model = new DefaultTableModel(data, columnNames);
              table = new JTable(model)
                   public String getToolTipText( MouseEvent e )
                        int row = rowAtPoint( e.getPoint() );
                        int column = columnAtPoint( e.getPoint() );
                        if (row == 0)
                             return null;
                        else
                             return row + " : " + column;
              table.setRowSelectionInterval(0, 0);
              table.setColumnSelectionInterval(0, 0);
              table.setRowHeight(0,34);
              table.setRowHeight(1,34);
              table.setRowHeight(2,34);
              table.setDefaultRenderer(Object.class, new TextAreaRenderer(2));
              JScrollPane scrollPane = new JScrollPane( table );
              getContentPane().add( scrollPane );
              JPanel buttonPanel = new JPanel();
              getContentPane().add( buttonPanel, BorderLayout.SOUTH );
              JButton button2 = new JButton( "Update Cell" );
              buttonPanel.add( button2 );
              button2.addActionListener( new ActionListener()
                   public void actionPerformed(ActionEvent e)
                        int row = table.getSelectedRow();
                        int column = table.getSelectedColumn();
                        String value = (String)table.getValueAt(row, column);
                        value += value;
                        table.setValueAt( value, row, column );
                        DefaultTableModel model = (DefaultTableModel)table.getModel();
                        model.fireTableCellUpdated(row, column);
                        table.requestFocus();
         public static void main(String[] args)
              TestTable frame = new TestTable();
              frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
              frame.pack();
              frame.setVisible(true);
         private class TextAreaRenderer extends JTextArea implements TableCellRenderer
              public TextAreaRenderer(int displayRows)
                   setRows(displayRows);
                   setLineWrap( true );
              public Component getTableCellRendererComponent(JTable table,
                                             Object value,
                                             boolean isSelected,
                                             boolean hasFocus,
                                             int row,
                                             int column)
                   setText( value.toString() );
                   Dimension d = getPreferredSize();
                   int maximumHeight = getRows() * getRowHeight();
                   if (d.height > maximumHeight)
                        setSize(d);
                        int offset = viewToModel( new Point(d.width, maximumHeight - 1) );
                        replaceRange( "...", offset-3, getDocument().getLength() );
                   return this;
    }

  • Accidentally changed an annotation in my ADE annotations folder to open with PDF, It has changed them all.  How can I change them back or is it ok to delete the whole folder

    I went into my documents/ ADE and opened the annotations folder.  I changed the read with on one to PDF and it has changed them all.  How can I change it back.  Or is it ok to delete the whole folder. I don't have any annotations I want to save.

    I went into my documents/ ADE and opened the annotations folder.  I changed the read with on one to PDF and it has changed them all.  How can I change it back.  Or is it ok to delete the whole folder. I don't have any annotations I want to save.

  • How to delete the specified line in file?

    How to delete the specified line in file? In case of deleting a specified line in a file, how to do?
    Line 1
    Line 2
    Line 3
    Line 4
    Line 5
    The case is a file including the above content. Now I wanna to delete the "Line 3" and how to realize the action in Java?

    An alternative solution can be :
    import java.io.LineNumberReader;
    import java.io.IOException;
    import java.io.File;
    import java.io.FileReader;
    import java.io.BufferedWriter;
    import java.io.FileWriter;
    import java.io.PrintWriter;
    public class LineDeleter {
    public static void main(String args[]){
    try {
    //suppose you want to delete line 3
         int lineToBeDeleted = 3;
         File f = new File("line.txt");
         long fileSize = f.length();
    //Wrap the FileReader with a LineNumberReader. It will help you
    //identify the lines.
    LineNumberReader lnr = new LineNumberReader( new FileReader(f));
    //Wrap the FileWriter object with BufferedWriter object. Create it with the buffersize
    //equal to the file size.
         BufferedWriter bw = new BufferedWriter(new FileWriter(new File("line1.txt")),(int)fileSize);
    //Wrap BufferedWriter object with PrintWriter so that it allows you
    //to print line by line
    PrintWriter pw = new PrintWriter(bw);
         String s=null;
         while ( (s=lnr.readLine())!=null ){
              System.out.println(s);
              int lineNumber = lnr.getLineNumber();
    //match the line number
              if(! (lineNumber==lineToBeDeleted)){
                   pw.println(s);
              pw.flush();
              lnr.close();
              pw.close();
         catch(Exception e){System.out.println(e);}
    If you want you can rename the line1.txt to the original file name.
    I hope this helps.Good luck!!!!!!

  • For the new iPhone 5s - is there not an option anymore to edit imessages without deleting the whole stream?  There are some things I need to keep within a stream and some not necessary, and it looks as like no editing within a conversation?

    For the new iPhone 5s - is there not an option anymore to edit imessages without deleting the whole stream?  There are some things I need to keep within a stream and some not necessary, and it looks as like no editing within a conversation?

    Now I also know about pulling the message to the left to see the time stamp.  Good to know, although I preferred it being right where I could see it without having to do a swipe or keystroke. 

  • Finding multiple strings in a text file and deleting the entire line

    Get-Content c:\output-Copy.txt | Where-Object {$_ -notmatch 'something1', 'something2', 'something3', 'something4' } | Set-Content temp.txt
    Above is the program that when it has 1 argument in the -notmatch part will find the specific string and delete the entire line. I need to be able to use multiple strings for my search, I am totally drawing a blank on this and I know its something REALLY
    simple but my brain is fried. The above code will work IF i only leave 'something1' and delete the rest. I need to find MULTIPLE matches and remove them all at once, what is a good way to accomplish this.

    You can use an alternating regex, like this:
    Get-Content c:\output-Copy.txt |
    Where-Object {$_ -notmatch 'something1|something2|something3|something4' } |
    Set-Content temp.txt
    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

  • HT201272 I made a purchase of an album on iTunes...somehow I deleted the whole album from my iMac and now when I go back to my purchases it does not give me the option to download the whole album again, instead it gives me the option of plaing them...plea

    I made a purchase of an album on iTunes...somehow I deleted the whole album from my iMac and now when I go back to my purchases it does not give me the option to download the whole album again, instead it gives me the option of plaing them...please help!!

    Where are you looking to download them from ? You might be able to redownload them via the Purchased link under Quicklinks on the right-hand side of the iTunes store homepage on your Mac's iTunes. If that album shows there but doesn't have the cloud symbol against it for redownloading then that implies that it's still in your iTunes library

  • In "Notes", typing a hyphen deletes the entire line of text

    Has anybody encounterd goofiness in Notes?  I am frequently experiencing problems where Notes is deletes my typing.  This happens often at random times but if I switch to a different line on the page it will let me type.  Typing a hyphen will ALWAYS delete the entire line of text.
    Perplexed... has been going on for months.  Did not used to happen....

    Excellent suggestion, Peter.
    Tabbing proved to be a little dodgy, simply because my paragraphs are set to Justify with Last Line Aligned Left, and so depending on where I am in a line of text, I'd have to get really deep into tinkering with my tab settings. But just using the space bar and tweaking the character styles yielded fine results.
    Thanks!
    (Now if only ID6 would print correctly when duplexing on my HP 8100 on letter-sized paper…)

  • ITunes doesn't display the whole line

    Most of my iTunes looks like this:
    I have plenty of space on the screen, but can't see the whole line. Anyone know how to fix it.

    You signature shows you have Mac OS X 10.7.4.
    If you do not have an Info tab in iTunes, you have Mac OS X 10.9.
    You sync Contacts & Calendars using iCloud, not iTunes.

  • To delete the last line of the internal table

    How to delete the last line of the internal table.???????
    The list which gets displayed from the internal table adds a dummy line at the last which shows zeros and zeros.all the otheer selections are perfect.i just want to delete the last line which comes as zero zero.is there any way to do it...

    Quite Easy......Use Describe command to Count the Total Number of Table Lines, and then Delete the Last Line using Index.
    Data L like sy-tabix.
    Describe Table Itab Lines L.
    Delete itab index L.

Maybe you are looking for