Can you get a list of OSX fonts somehow?
-
http://stackoverflow.com/a/3159997/486990
Either:
system('foobarCommand')
The latter will return the output - the former will output to standard output but return true/false.
` >> system('echo hi')
hi
=> trueecho hi
=> "hi\n"`(This was using IRB from a system console)
However, using Ruby Console:
but
-
System IRB console:
>> system 'echo hi' hi => true
SketchUp Console:
` > system 'echo hi'
truesystem 'fc-list'
false`What gives?
-
How about something like...
fontList = system(
fc-list : family)
??
Do you need to specify the 'shell-type' in the line like ?
fontList=system(
#!/bin/bash usr/bin/fc-list : family)
When it works, then is it fast enough ? -
@tig said:
How about something like...
fontList = system(
fc-list : family)
??See my previous post - the commands work in native consoles, but not in in SketchUp console - it doesn't appear to capture the output.
-
But the surely surrounding ` ``` '' "" etc can produce different results ??
So... are they all foobar?My other example tried to force it to run as a 'bash' shell... Is that possible?
Not having a MAC available does somewhat curtail my help in this area
-
@thomthom said:
the commands work in native consoles, but not in in SketchUp console
Maybe they are using stderr instead of stdout? You could test on the command line:
fc-list : family > out fc-list : family 2> err
-
@tig said:
But the surely surrounding ` ``` '' "" etc can produce different results ??
So... are they all foobar?My other example tried to force it to run as a 'bash' shell... Is that possible?
They all return
false
. -
@jim said:
Maybe they are using stderr instead of stdout? You could test on the command line:
fc-list : family > out fc-list : family 2> err
nada
-
Tried to output to file:
fc-list : family >> ~/Desktop/fonts.txt
Empty when run from within SketchUp, populated when run in a native console.
Something is messed up with the messaging system!
-
system(
fc-list : family | out)
?
running out of permutations... -
Won't that just list fonts with "out" in them?
-
The 'grep' is for pattern matching...
The | pipes/passes the output to something else ['out'].
What do you call the 'output' on a MAC ??
The > puts the output into a file.
The >> appends the output to a file.
How do you 'pass/send' something ? -
TT
what osx are you running.
'shell' change to AT&T version with 10.5 , so the syntax needs to be checkedFontBook has had lots of revisions/additions
and those osascripts run it in the background, take miliseconds on my mac.the nice thing is people could set a 'SU 3D Font Collection in fontbook and you can allow them to use just those
john -
@driven said:
what osx are you running.
10.5
@driven said:
'shell' change to AT&T version with 10.5 , so the syntax needs to be checked
But it works in the system console, and it works from IRB calling system command - but not from SketchUp calling system command.@driven said:
FontBook has had lots of revisions/additions
and those osascripts run it in the background, take miliseconds on my mac.Mine took a noticeable lag the first time I ran it, but quick the next runs. And Font Book's icon appeared in the dock.
-
@thomthom said:
But it works in the system console, and it works from IRB calling system command - but not from SketchUp calling system command.
it is possible to get an output to Ruby Console using echo <dev/nul, but I need to dig thru for a working example..
@unknownuser said:
Mine took a noticeable lag the first time I ran it, but quick the next runs. And Font Book's icon appeared in the dock.
I think I would run only once, hold the list in the plugin, but add an update function/item for people who add fonts to FontBook [very few]...
added to the end of the osascript should close it after use-e 'tell application "Font Book" to quit' -e 'end'
john -
I've been trying loads of different ways to get the exact font list that SU shows under 'Window' >> 'Show Fonts' all 297 on my mac, this is by far the easiest
macFonts=[] macFonts=(`osascript -e 'tell application "Font Book" to set macFonts to name of every font family'`).split(",").uniq.each {|a| a.strip! if a.respond_to? ;strip! }.sort quitFontBook=(`osascript -e 'tell application "Font Book" to quit'`) if macFonts.length > 1 then quitFontBook end macFonts.length
john
-
I'll try it on my mac
-
@thomthom said:
I'll try it on my mac
when you do...
For seeing if they all will work from code, I've been trying to make a '3d Font Sampler' using the 'macFont' array for both the 'string' and 'font' and the index number for 'z' position, but I keep screwing it up... could you cobble something together? or pointers...another way to get the SU Font List, but not in ruby
tell application "Sketchup" activate end tell tell application "System Events" if UI elements enabled then tell process "SketchUp" click the menu "Window" of menu bar 1 delay 1 click menu item "Show Fonts" of menu "Window" of menu bar 1 delay 1 tell window "Fonts" set results to value of text field 1 of every row of table 1 of scroll area 3 delay 1 end tell end tell tell application "System Events" tell process "SketchUp" click the menu "Window" of menu bar 1 delay 1 click menu item "Hide Fonts" of menu "Window" of menu bar 1 delay 1 return results end tell end tell else tell application "System Preferences" activate set current pane to pane "com.apple.preference.universalaccess" display dialog "UI element scripting is not enabled. Check \"Enable access for assistive devices\"" end tell end if end tell
-
I managed to get a list to manually test all the fonts [via copy/paste]... they all work
but I can't work out how I can have each as a group, or how even how to get SU to just make them...macFonts.each_with_index do |item, index| puts %(Sketchup.active_model.entities.add_3d_text("#{item}" , TextAlignCenter, "#{item}" , true, false, 1.0, 0.0, #{index}, true, 0.05)) end
works as a puts which I can copy/paste in batches to make, but fails as a direct method
macFonts.each_with_index do |item, index| Sketchup.active_model.entities.add_3d_text("#{item}" , TextAlignCenter, "#{item}" , true, false, 1.0, 0.0, #{index}, true, 0.05) end
...why???
john -
Oh it's just a head-smackin' boo-boo.
Thez
arg takes aNumeric
and theindex
is already aNumeric
subclass (Integer
,)
so you do not use the#{
...}
string replacement syntax.
(But you don't want to stack them vertically, move them -Y so they are all in a column (see below.)Another quirk about
add_3d_text()
, is that unlike the OEM tool, the Ruby method does not put the primitives into a group.So we encourage you to create group(s) then call the method on the group's
Entities
collection:macFonts.each_with_index do |item, index| grp = Sketchup.active_model.entities.add_group() grp.entities.add_3d_text( "#{item}", TextAlignCenter, "#{item}", true, false, 1.0, 0.0, 0.0, true, 0.05 ) grp.name= item grp.move!( Geom;;Transformation.new(Geom;;Vector3d.new(0,-index,0)) ) end
Advertisement