R
Richard Fairbanks
Greetings, folks!
I need to be able to capitalize words inside quote marks, as part of a
string of words. I need to use proper publishing capitalization
protocols which is more involved than simply making the first letter of
each word uppercase. Thus the appended script is greatly truncated!
I would be very grateful if someone could please advise me on why the
following doesn’t work as part of a repeating loop or with typographic
quote marks, but does work as a simple standalone script.
Blessings and thank you!
Richard Fairbanks
----
The following does work, but only if the first quote is a straight
quote: ' or ". It doesn’t work with typesetter marks: ‘ or “
#!/usr/bin/env ruby
require 'rubygems'
require "jcode"; $KCODE = "UTF8"
require 'appscript'; include Appscript
require 'osax'; include OSAX
# copy the text: "abc"
item = osax.the_clipboard()
item1 = item[0,1]
item2 = item[1..-1]
item = item1 + item2.capitalize!
osax.set_the_clipboard_to(item) #=> "Abc"s
----
BUT it doesn’t work at all as part of a loop:
#!/usr/bin/env ruby
require 'rubygems'
require "jcode"; $KCODE = "UTF8"
require 'appscript'; include Appscript
require 'osax'; include OSAX
openingQuoteMark = ["'", "\"", "‘", "’", "“"]
# get the text to be processed:
theString = osax.the_clipboard()
theWords = theString.split # convert the text to an array of the
words
theWords.each do |item|
charList = item.split(//) # create an array of the word’s
characters
# first check to see if there is an opening quote mark
unless openingQuoteMark.include?(charList[0]) # if the word doesn’t
start with a quote mark. If it does, this will only try to capitalize
the quote mark!
# this works fine
item = item.capitalize!
else
# but the following doesn’t work
# to test: copy me to the clipboard with "abc"
item1 = item[0,1]
item2 = item[1..-1]
item = item1 + item2.capitalize!
osax.say "but it does run!"
end
end
# convert the full list to a string with a space between each item
theWords = theWords * ' '
# set the clipboard to the processed string
osax.set_the_clipboard_to(theWords)
I need to be able to capitalize words inside quote marks, as part of a
string of words. I need to use proper publishing capitalization
protocols which is more involved than simply making the first letter of
each word uppercase. Thus the appended script is greatly truncated!
I would be very grateful if someone could please advise me on why the
following doesn’t work as part of a repeating loop or with typographic
quote marks, but does work as a simple standalone script.
Blessings and thank you!
Richard Fairbanks
----
The following does work, but only if the first quote is a straight
quote: ' or ". It doesn’t work with typesetter marks: ‘ or “
#!/usr/bin/env ruby
require 'rubygems'
require "jcode"; $KCODE = "UTF8"
require 'appscript'; include Appscript
require 'osax'; include OSAX
# copy the text: "abc"
item = osax.the_clipboard()
item1 = item[0,1]
item2 = item[1..-1]
item = item1 + item2.capitalize!
osax.set_the_clipboard_to(item) #=> "Abc"s
----
BUT it doesn’t work at all as part of a loop:
#!/usr/bin/env ruby
require 'rubygems'
require "jcode"; $KCODE = "UTF8"
require 'appscript'; include Appscript
require 'osax'; include OSAX
openingQuoteMark = ["'", "\"", "‘", "’", "“"]
# get the text to be processed:
theString = osax.the_clipboard()
theWords = theString.split # convert the text to an array of the
words
theWords.each do |item|
charList = item.split(//) # create an array of the word’s
characters
# first check to see if there is an opening quote mark
unless openingQuoteMark.include?(charList[0]) # if the word doesn’t
start with a quote mark. If it does, this will only try to capitalize
the quote mark!
# this works fine
item = item.capitalize!
else
# but the following doesn’t work
# to test: copy me to the clipboard with "abc"
item1 = item[0,1]
item2 = item[1..-1]
item = item1 + item2.capitalize!
osax.say "but it does run!"
end
end
# convert the full list to a string with a space between each item
theWords = theWords * ' '
# set the clipboard to the processed string
osax.set_the_clipboard_to(theWords)