Non-Scrivener Specific AppleScript Question

ed
edmo
Posts: 47
Joined: Wed Oct 25, 2006 6:06 pm
Location: Vancouver, BC, CAN

Fri Sep 11, 2009 6:02 pm Post

@flow & @gr - Thanks again to both of you for the further assistance. The info you provided helped me to cobble together an acceptable solution in the following form:
<CODE>
set font of every attribute run whose (font does not start with "Helvetica" and (font contains "BoldOblique" or font contains "BoldItalic")) to "Helvetica-BoldOblique"
set font of every attribute run whose (font does not start with "Helvetica" and (font contains "Oblique" or font contains "Italic")) to "Helvetica-Oblique"
set font of every attribute run whose (font does not start with "Helvetica" and font contains "Bold") to "Helvetica-Bold"
set font of every attribute run whose (font does not start with "Helvetica") to "Helvetica"
<CODE>
It seems to work quite a bit faster than a looped find & replace on attribute runs.

@flow - If you do end up looking any further into this and finding a better way to do it, I'm all ears. It's one of those things to me that feels like there ought to be a quick and easy way to do this via applescript, given how easy it is to do it in a document (select all, go to the Format>Font>Show Fonts menu, select Helvetica, et voila).

@gr - Thanks for the tip re. finding appleScript sites and forums. I have done much googling and bookmarking, though so far I have refrained from joining any additional forums. FWIW to know, I have only asked these questions in the Scriv forum as a next-to-last resort, after much research and many failed attempts. Don't want to impose on yourself and other busy writers, but since this is a place where so many bright (and helpful) lights hang out...

Thanks again, all.

fl
flow
Posts: 66
Joined: Tue Jul 24, 2007 12:16 am

Sat Sep 19, 2009 9:47 pm Post

Wow. Just took a look at this, and ... wow. I was expecting some challenges with this, but there were more than I imagined. A lot of the fonts have different naming conventions, which made for an interesting brain teaser this afternoon.

Your script seems to be the best solution. The only thing I'd note is that, as written, your script would not change fonts like "HelveticaCY" or "HelveticaNeue" to "Helvetica", but if you don't have those fonts on your system, then that's not an issue.

It is funny how system events would make this a piece of cake, but to change fonts in the background makes it a ... challenge.

ed
edmo
Posts: 47
Joined: Wed Oct 25, 2006 6:06 pm
Location: Vancouver, BC, CAN

Mon Sep 21, 2009 9:23 pm Post

@flow - thanks much for chiming back in on this and for letting me know about the "Helvetica Neue/CY" omissions, which I have now fixed.

For my further edification, if you feel like posting the "piece of cake" system events method of changing the font family to love to know it (I can see how to activate the font palette using keystrokes, but if that's the start of the method you're alluding to, I have no idea what to do next). Don't bother if your too busy or otherwise disinclined, though - I've already taken up a lot of your time with this.

Again, much appreciated.

fl
flow
Posts: 66
Joined: Tue Jul 24, 2007 12:16 am

Wed Sep 23, 2009 4:59 pm Post

Oops. Earlier in the conversation, when we were working with keeping the color, I was experimenting with Tex-Edit Plus as well TextEdit. In Tex-Edit Plus, the fonts are listed in the Font menu (and the "Show Fonts" option is there as well), and I was able to simply select the text and change the font without changing any of the other attributes. Tex-Edit Plus is more AppleScript-friendly than TextEdit.

User avatar
gr
Posts: 2272
Joined: Wed Feb 14, 2007 3:57 am
Platform: Mac + iOS
Location: Florida

Thu Sep 24, 2009 12:52 am Post

By the way, instead of adding special clauses for Helvetica versions, why not just drop the exclusion clauses:

Code: Select all

font does not start with "Helvetica"


The amount of overkill this would result in would probably be negligible.

--Greg

ed
edmo
Posts: 47
Joined: Wed Oct 25, 2006 6:06 pm
Location: Vancouver, BC, CAN

Thu Sep 24, 2009 5:05 pm Post

@flow - thanks for getting back to me about that.

@greg - your suggested method is the one I ended up going with, as we came to the same conclusion re. the negligible amount of overkill. Thanks for replying about it.