in

Quark Forums

Making a simple macro with AppleScript?

Last post 02-03-2012 5:24 AM by Jean-Marie Schwartz. 36 replies.
Page 1 of 3 (37 items) 1 2 3 Next >
Sort Posts: Previous Next
  • 01-26-2012 12:25 PM

    Making a simple macro with AppleScript?

    I've been using quark since it was distributed on floppy disks. So I'm embarrased to ask this...

    I'm trying to make a simple macro to find and change a control/space to a regular spacespace, quote mark to a quote mark, and an apostrophe to an apostrphe. I have been doing each one of these find/changes individually to every quark doc I make for a magazine. 

    Is an apple script the best way?

    Is there a tutorial anywhere for doing this?

  • 01-26-2012 2:46 PM In reply to

    • ubba
    • Not Ranked
    • Joined on 11-18-2006
    • Genoa, Italy
    • Posts 18

    Re: Making a simple macro with AppleScript?

  • 01-26-2012 3:41 PM In reply to

    Re: Making a simple macro with AppleScript?

    Thank you! I'll start digging.
  • 01-26-2012 4:20 PM In reply to

    Re: Making a simple macro with AppleScript?

    That was a good start. I see clearly how to do a simple find/change and created a script to test. But I don't even know what to do with it. I found this link and will start reading: http://www.mactech.com/articles/mactech/Vol.22/22.10/2210AppleScript/index.html . I don't know why I haven't used this before...it looks powerful and useful.
  • 01-27-2012 3:02 AM In reply to

    • Emma
    • Top 10 Contributor
    • Joined on 07-07-2004
    • Leeds, UK
    • Posts 1,185

    Re: Making a simple macro with AppleScript?

    Below is my base search and replace script. Works for basic text stuff, tabs and returns. But if you want to replace special spaces and so on, you need to export with XPress Tags, work on that text in a text editor and re-import it. All this can be done within Applescript. --Put what you want to search for inside the first quotes, --and what you want to replace it with inside the second. --2 examples are already completed --you can add as many of these as you like! SAndR(" ", "") SAndR("favor", "favour") SAndR("£", tab & "£") on SAndR(searchstring, replacestring) tell document 1 of application "QuarkXPress" -- the try...end try bit means it won't error if it doesn't find any instances of a given searchstring try set (every text of every story where it is searchstring) to replacestring end try end tell end SAndR
  • 01-27-2012 9:42 AM In reply to

    Re: Making a simple macro with AppleScript?

    Thank you Emma. It works great for text strings. My first script worked! You have created a monster...I'm going to start taking advantage of scripts. I'm looking forward to learning how to automate things. But this one didn't. I get a syntax error. SAndR(""", """) SAndR("'", "'") on SAndR(searchstring, replacestring) tell document 1 of application "QuarkXPress" try set (every text of every story where it is searchstring) to replacestring end try end tell end SAndR I'm trying to replace quote marks with quote marks and apostophe with apostrophe. This is to "smarten" them, which doesn't always import or paste in that way. the other item I want to replace is strange spaces that print like en spaces. That I solved by find/change space for space.
  • 01-27-2012 9:48 AM In reply to

    • Emma
    • Top 10 Contributor
    • Joined on 07-07-2004
    • Leeds, UK
    • Posts 1,185

    Re: Making a simple macro with AppleScript?

    Sorry to see that returns don't work in Chrome on this forum! Have been using Firefox for ages, which is fine, but migrated to Chrome and now my posts look daft again! Monsters - yes, that's what happens. You see the magic as your script works, and you want more... and more ... and more! I'm sure it's possible to put in 'literal' quotes and apostrophes, but for the life of me I can't recall how. You'd need to have your Quark Preferences set to typographers' quotes, or it wouldn't work anyway. Anyone??
  • 01-27-2012 9:53 AM In reply to

    Re: Making a simple macro with AppleScript?

    Firefox it is. Chrome is nice but I'm ditching it for other reasons, like adyield manager. Another topic I guess. This is with firefox:

    SAndR("'", "'")

    on SAndR(searchstring, replacestring)
        tell document 1 of application "QuarkXPress"
            try
                set (every text of every story where it is searchstring) to replacestring
            end try
        end tell
    end SAndR

    This does not work :-(

     

  • 01-28-2012 4:13 AM In reply to

    • ubba
    • Not Ranked
    • Joined on 11-18-2006
    • Genoa, Italy
    • Posts 18

    Re: Making a simple macro with AppleScript?

    Hi, hope I don't misunderstood, my english isn't so good :-)

    You can give a try with
    SAndR("'", ASCII character 213) -- convert single quote in typographic right single quote (I used ASCII numb, but  think it works fine also with the char)
    SAndR(" " & (ASCII character 213), " " & (ASCII character 212)) -- now I fix the instances of left single quotes, with the previous passage I obtained (eg.) ’my quoted word’ (the first quote is wrong) and now I fix it
    SAndR(" \"", " " & (ASCII character 210)) -- it's the turn of left double quote
    SAndR("\" ", (ASCII character 211) & " ") -- and of right double quote
    


    All the play is supposing that the spaces (blanks) are in their place...
    For example the single and double LEFT quotes are recognized by the blank before them
    and the right ones by the blank after.

    Hope this help.

    ciao!
  • 01-28-2012 4:45 AM In reply to

    • ubba
    • Not Ranked
    • Joined on 11-18-2006
    • Genoa, Italy
    • Posts 18

    Re: Making a simple macro with AppleScript?

    One thing more...

     

    Here below a little script to get the ASCII numbers of text selected in QXP:

     

    tell application "QuarkXPress"
    	activate
    	try
    		class of selection = text
    		if contents of selection = "" then error
    	on error
    		display dialog "You don't have any text in selection!" & return & return & "You must select characters or words!" buttons "Stop" default button 1 with icon stop
    		return
    	end try
    	
    	set ascii_tags to {"(ASCII character ", ")"}
    	
    	set my_sel to contents of selection
    	
    	set default_answer to ""
    	
    	repeat with i from 1 to count of my_sel
    		if i = (count of my_sel) then
    			set ts to ""
    		else
    			set ts to return
    		end if
    		set default_answer to default_answer & (item 1 of ascii_tags) & (ASCII number (item i of my_sel)) & (item 2 of ascii_tags) & ts
    	end repeat
    	
    	if (count of my_sel) > 1 then
    		set chars_word to "characters"
    		set pronome to "their"
    		set pronome2 to "They"
    		set numbers_word to "numbers"
    	else
    		set chars_word to "character"
    		set pronome to "its"
    		set pronome2 to "It"
    		set numbers_word to "number"
    	end if
    	
    	display dialog "Your selected " & (count of my_sel) & " " & chars_word & "." & return & return & "Here below " & pronome & " ASCII " & numbers_word & "." & return & return & pronome2 & "'ll be copied in the clipboard." default answer default_answer buttons {"OK"} default button 1 with icon 1
    	
    	set the clipboard to default_answer
    	
    end tell
    

    Ciao!

     

    - - - - 

    jo

  • 01-30-2012 5:03 AM In reply to

    • ikunz
    • Not Ranked
    • Joined on 05-14-2010
    • Posts 13

    Re: Making a simple macro with AppleScript?

    Hi Emma,

    do you know any way to do a search and replace with placeholders?

    I would like to search for "/0XX" or "/9XX" and replace them with "/0yy" or "/9yy"

    And would like to tell the script what to search for (XX) and what to replace with (yy), somehow like:

    display dialog "what to search for" default answer "" buttons {"Cancel", "OK"} default button 2
    set the search_string to the text returned of the result
    if the search_string is not "" then exit repeat
    end repeat
    repeat
    display dialog "what to replace with:" default answer "" buttons {"Cancel", "OK"} default button 2
    set the replacement_string to the text returned of the result
    if the search_string is not "" then exit repeat


    I need that placeholder since XX also could be somewhere in the textarea i dont want to change, i only will change the last two digits of the numbers ending with /nnn

    Any help appreciated.
    Rene
  • 01-30-2012 7:28 AM In reply to

    Re: Making a simple macro with AppleScript?

    You would want to use concatenation, like this: set Searchstring to "/0" & My_XX
    -- where My_XX is a variable containing the text returned of your dialog: set My_XX to text returned of (display dialog "what to search for"…).

    There is a part of a repeat loop in your code below (or above, depending) that doesn't seem to work as is. Are you aware of it? So the line: if the search_string is not "" then exit repeat would most probably need to be if search_string IS "" then return
    Unless I'm missing sth?

    Jean-Marie Schwartz

    > Mac Pro Quad Core Intel 2.8 GHz, OS X.6.8, Quark XPress 9.2, Adobe CS5 <
  • 01-30-2012 7:40 AM In reply to

    Re: Making a simple macro with AppleScript?

    Thank you ubba, I'll be giving that a try later today.

  • 01-30-2012 8:09 AM In reply to

    • ikunz
    • Not Ranked
    • Joined on 05-14-2010
    • Posts 13

    Re: Making a simple macro with AppleScript?

    Thanks for the hint about the loop, so far it worked with /.is not "" then exit repeat./

    Now with /.is "" then return/. it really is a loop, i cant get any further.

    I dont know where to use concatenation. Can you give me an example for my script:
    repeat
    display dialog "what to search for" default answer "" buttons {"Cancel", "OK"} default button 2
    set searchstring to the text returned of the result
    if searchstring is not "" then exit repeat
    end repeat
    repeat
    display dialog "what to replace with" default answer "" buttons {"Cancel", "OK"} default button 2
    set replacestring to the text returned of the result
    if replacestring is not "" then exit repeat
    end repeat

    on SearchAndReplace1(searchstring, replacestring)
    tell document 1 of application "QuarkXPress"
    set (every text of every story where it is searchstring) to replacestring
    end tell
    end SearchAndReplace1
  • 01-30-2012 9:38 AM In reply to

    Re: Making a simple macro with AppleScript?

    OK I see the repeat loop and understand the way you script it now. I've never used a DD in a repeat loop. So the exit repeat is fully understandable now. Leave it.
    As for the concat I told you about, it's to be inserted after the repeat loops, in 2 lines: set searchstring to "/0" & searchstring | set replacestring to "/0" & replacestring | my SearchAndReplace1(searchstring, replacestring)

    Is it OK? (Not tested.)

    Jean-Marie Schwartz

    > Mac Pro Quad Core Intel 2.8 GHz, OS X.6.8, Quark XPress 9.2, Adobe CS5 <
Page 1 of 3 (37 items) 1 2 3 Next >
Powered by Community Server (Commercial Edition), by Telligent Systems