sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Can you get a list of OSX fonts somehow?

    Scheduled Pinned Locked Moved Developers' Forum
    110 Posts 6 Posters 13.9k Views 6 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D Offline
      driven
      last edited by

      cheers again,
      linespacing is a nice touch.
      all the code runs, returns nil. then draws view with the new groups, changing chuncksize doesn't alter that.
      it doesn't take too long.
      only two fonts don't fully form, may be the size, but not bad really.

      so, the main purpose was to check that the osascript fonts were the right one, and they are...

      and I learnt a little ruby
      thanks dan
      john

      learn from the mistakes of others, you may not live long enough to make them all yourself...

      1 Reply Last reply Reply Quote 0
      • Dan RathbunD Offline
        Dan Rathbun
        last edited by

        It occurs to me that because the fontsize is only 1 inch, that many arc segments are ridiculously small, perhaps overloading the SketchUp engine.

        Try setting:
        fsize = 1.0.feet linspacing = 1.25.feet

        ❓

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • D Offline
          driven
          last edited by

          Yeh, I tried that, didn't make a lot of difference,
          I use 100 and 120

          fsize needs to be in inches, doesn't it?a sample of the sample

          learn from the mistakes of others, you may not live long enough to make them all yourself...

          1 Reply Last reply Reply Quote 0
          • Dan RathbunD Offline
            Dan Rathbun
            last edited by

            @driven said:

            fsize needs to be in inches, doesn't it?

            1.0.feet will return a Length object == 12"

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • D Offline
              driven
              last edited by

              I missed the dot... oops should stick to copy/paste

              learn from the mistakes of others, you may not live long enough to make them all yourself...

              1 Reply Last reply Reply Quote 0
              • thomthomT Offline
                thomthom
                last edited by

                I tried this:

                <span class="syntaxdefault"><br />t</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">Time</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">now<br />&nbsp;&nbsp;&nbsp;&nbsp;macFonts</span><span class="syntaxkeyword">=[]<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">macFonts</span><span class="syntaxkeyword">=(`</span><span class="syntaxstring">osascript&nbsp;-e&nbsp;'tell&nbsp;application&nbsp;"Font&nbsp;Book"&nbsp;to&nbsp;set&nbsp;macFonts&nbsp;to&nbsp;name&nbsp;of&nbsp;every&nbsp;font&nbsp;family'</span><span class="syntaxkeyword">`).</span><span class="syntaxdefault">split</span><span class="syntaxkeyword">(</span><span class="syntaxstring">","</span><span class="syntaxkeyword">).</span><span class="syntaxdefault">uniq</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each&nbsp;</span><span class="syntaxkeyword">{|</span><span class="syntaxdefault">a</span><span class="syntaxkeyword">|&nbsp;</span><span class="syntaxdefault">a</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">strip</span><span class="syntaxkeyword">!&nbsp;if&nbsp;</span><span class="syntaxdefault">a</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">respond_to</span><span class="syntaxkeyword">?&nbsp;;</span><span class="syntaxdefault">strip</span><span class="syntaxkeyword">!&nbsp;}.</span><span class="syntaxdefault">sort<br />&nbsp;&nbsp;&nbsp;&nbsp;quitFontBook</span><span class="syntaxkeyword">=(`</span><span class="syntaxstring">osascript&nbsp;-e&nbsp;'tell&nbsp;application&nbsp;"Font&nbsp;Book"&nbsp;to&nbsp;quit'</span><span class="syntaxkeyword">`)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;</span><span class="syntaxdefault">macFonts</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">length&nbsp;</span><span class="syntaxkeyword">>&nbsp;</span><span class="syntaxdefault">1<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;then&nbsp;quitFontBook<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end<br />&nbsp;&nbsp;&nbsp;&nbsp;macFonts</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">length<br />puts&nbsp;Time</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">now</span><span class="syntaxkeyword">-</span><span class="syntaxdefault">t<br /></span>
                

                On the first run it yielded 8.500629 seconds.

                The next was 2.422791 and 2.286048 seconds.

                If I comment out the code the closes Font Book the times are 0.241677 and 0.228576.

                So the overhead of launching Font Book is just all too high.

                Thomas Thomassen — SketchUp Monkey & Coding addict
                List of my plugins and link to the CookieWare fund

                1 Reply Last reply Reply Quote 0
                • D Offline
                  driven
                  last edited by

                  but you only need to run once, and write the 'Users' personal font-list to file [save in TT-Lib]
                  if the User instals new fonts [very rare] they could delete the file and make a new one, or that could be an option?
                  john

                  learn from the mistakes of others, you may not live long enough to make them all yourself...

                  1 Reply Last reply Reply Quote 0
                  • thomthomT Offline
                    thomthom
                    last edited by

                    That could be a fallback. But I'm still hoping to find a method that works quickly which I can use. the fc-list is fast - it's just that I cannot get the output from that. ..and for some reason I cannot seem to direct the output to a file... Maybe one can trigger a new console command that might actually be able to write to file?

                    Thomas Thomassen — SketchUp Monkey & Coding addict
                    List of my plugins and link to the CookieWare fund

                    1 Reply Last reply Reply Quote 0
                    • TIGT Offline
                      TIG Moderator
                      last edited by

                      But this is bringing us full circle 😕
                      You might as well try to use something like:
                      fonts_file="\"path/to/fonts.txt\"" system(fc-list : file family | grep /Library > fonts_file)
                      Or something similar ? #{fonts_file} ??... Whatever can be made to work !
                      Or even a more convoluted
                      UI.openURL('file:///'+commandfilepath)
                      And then read the ttf-font names from the fonts_file 😕

                      There is a simple solution [KISS]...
                      In my own [far less sophisticated] '2dText' tool and some of my similar tools like 'AreaTextTag', which make 3dText as '2d flat editable text', my drop-down-list of the available fonts is simply a combined list of some ttf fonts that are usually shipped with recent PCs A_N_D MACs.
                      For the reduced list in the AreaTextTag it a simple array of a reduced list, typed in the code that the user can customize. In the more wide-ranging 2dText tool it's read in a simple txt text file ['2DtextTool_Fonts.txt' in the tool's subfolder] of the 44 common font-names - the user can edit this [there are instructions in the tool's Help] - either to remove unwanted ones [e.g. in case he doesn't use 'Wingdings' very much], or to add custom one he has also installed on his computer [like 'Architext' or 'Consolas'] that are not in the default combo list... This allows the user to have their own customized fonts list and it's not that hard to alter/update/customize either... 😕

                      TIG

                      1 Reply Last reply Reply Quote 0
                      • Dan RathbunD Offline
                        Dan Rathbun
                        last edited by

                        Other option(s):

                        (a) Use UI.openpanel to let users manually pick font files, that are then added to the plugin's fontlist (kept as a hash file in the plugin's folder. The file distro's with a base set of standard Mac fonts.)

                        (b) Use the SDK and C/C++/Objective-C to get the list of Fonts Sketchup knows.

                        (From memory, I do think Sketchup's known fonts is exposed in the SDK.)

                        I'm not here much anymore.

                        1 Reply Last reply Reply Quote 0
                        • D Offline
                          driven
                          last edited by

                          I've found the KISS Applescript version, just figuring out if it's easier to strip the results first or in ruby.
                          the basic can then run as osascript...

                          set search1 to do shell script "mdfind -onlyin /Library/Fonts 'kMDItemContentTypeTree = \"public.truetype-ttf-font\"'" as text
                          set search2 to do shell script "mdfind -onlyin ~/Library/Fonts 'kMDItemContentTypeTree = \"public.truetype-ttf-font\"'" as text
                          

                          results look like this
                          %(#0000FF)[/Library/Fonts/NISC18030.ttf
                          /Library/Fonts/Kai.ttf
                          /Library/Fonts/Hei.ttf
                          /Library/Fonts/BiauKai.ttf
                          /Library/Fonts/Apple LiSung Light.ttf
                          /Library/Fonts/Apple LiGothic Medium.ttf
                          /Library/Fonts/Microsoft/Lucida Console.ttf
                          /Library/Fonts/Microsoft/Candara Bold Italic.ttf]

                          also, I think if a plugins is offering font manipulation for artistic usage, it should have all the 'SU' fonts and let the User decide which to use
                          john

                          learn from the mistakes of others, you may not live long enough to make them all yourself...

                          1 Reply Last reply Reply Quote 0
                          • thomthomT Offline
                            thomthom
                            last edited by

                            So that returns the filenames, but do the filenames represent the font names exactly?

                            I know that I would not be able to do that with the fonts on a Windows machine as they usually are abbreviations.

                            Thomas Thomassen — SketchUp Monkey & Coding addict
                            List of my plugins and link to the CookieWare fund

                            1 Reply Last reply Reply Quote 0
                            • Dan RathbunD Offline
                              Dan Rathbun
                              last edited by

                              @thomthom said:

                              I know that I would not be able to do that with the fonts on a Windows machine as they usually are abbreviations.

                              XP
                              %(#004080)[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts]

                              reg_fonts_on_win.PNG

                              I'm not here much anymore.

                              1 Reply Last reply Reply Quote 0
                              • TIGT Offline
                                TIG Moderator
                                last edited by

                                I suspect that the ttf file name is not always the font name 😒

                                MAC's 'fc-list' will provide the font-name, font-family etc -
                                I can't believe that 'we' can't get it to write the list to a variable using system(...) 😕
                                Have you tried something like this?
                                font_list=system(fc-list : family | cat)
                                or similar, where the output gets piped to something that can return a value like 'cat' ?
                                OR perhaps:
                                font_list=system(cat (fc-list : family))
                                OR probably with 'escaped' (), more like:
                                font_list=system(cat (fc-list : family))
                                😕

                                TIG

                                1 Reply Last reply Reply Quote 0
                                • thomthomT Offline
                                  thomthom
                                  last edited by

                                  @tig said:

                                  I can't believe that 'we' can't get it to write the list to a variable using system(...) 😕

                                  Yea, I wish I knew why this is mis-behaving inside SketchUp. 😕

                                  Thomas Thomassen — SketchUp Monkey & Coding addict
                                  List of my plugins and link to the CookieWare fund

                                  1 Reply Last reply Reply Quote 0
                                  • TIGT Offline
                                    TIG Moderator
                                    last edited by

                                    Have you tried any of my 'convolutions', to redirect / pipe its output to some other function that then might successfully return the values to 'system' ?
                                    As it does several 'lines' of output in the console can we pipe it through a loop ?
                                    Or like font_list=system(cat ($(fc-list : family)))
                                    Perhaps with some \ escaping of the various () ???

                                    TIG

                                    1 Reply Last reply Reply Quote 0
                                    • thomthomT Offline
                                      thomthom
                                      last edited by

                                      Not the recent ones. I only have access to a Mac at home, and last week I haven't been home for very long - certainly no time to test anything. 😞

                                      Thomas Thomassen — SketchUp Monkey & Coding addict
                                      List of my plugins and link to the CookieWare fund

                                      1 Reply Last reply Reply Quote 0
                                      • TIGT Offline
                                        TIG Moderator
                                        last edited by

                                        So there's still hope...
                                        Perhaps driven etc can try...
                                        I have no MAC access either...

                                        TIG

                                        1 Reply Last reply Reply Quote 0
                                        • D Offline
                                          driven
                                          last edited by

                                          sticking with things we know return in console

                                          > ttfList=(find ~/Library/Fonts/*.ttf`)
                                          /Users/johns_iMac/Library/Fonts/Momo.ttf
                                          /Users/johns_iMac/Library/Fonts/Tkds9crd.ttf
                                          /Users/johns_iMac/Library/Fonts/machtgth.ttf
                                          /Users/johns_iMac/Library/Fonts/machtssr-gm.ttf

                                          fontsM=(mdls -raw -name com_apple_ats_name_family ~/Library/Fonts/momo.ttf +
                                          mdls -raw -name com_apple_ats_name_family ~/Library/Fonts/Tkds9crd.ttf +
                                          mdls -raw -name com_apple_ats_name_family ~/Library/Fonts/machtgth.ttf +
                                          mdls -raw -name com_apple_ats_name_family ~/Library/Fonts/machtssr-gm.ttf)
                                          (
                                          Momo
                                          )(
                                          Trek
                                          )(
                                          "Machine Tool Gothic"
                                          )(
                                          "Machine Tool SanSerif"
                                          )this is a quick manual cobble, but it could be coerced, john edit: or this > fontsM=(mdls -raw -name com_apple_ats_name_full ~/Library/Fonts/momo.ttf +
                                          mdls -raw -name com_apple_ats_name_full ~/Library/Fonts/Tkds9crd.ttf +
                                          mdls -raw -name com_apple_ats_name_full ~/Library/Fonts/machtgth.ttf +
                                          mdls -raw -name com_apple_ats_name_full ~/Library/Fonts/machtssr-gm.ttf)
                                          (
                                          Momo
                                          )(
                                          "Trek DS9 Credits Text"
                                          )(
                                          "Machine Tool Gothic"
                                          )(
                                          "Machine Tool SanSerif"
                                          )or for completeness > fontsM=(mdls -raw -name kMDItemFonts ~/Library/Fonts/momo.ttf +
                                          mdls -raw -name kMDItemFonts ~/Library/Fonts/Tkds9crd.ttf +
                                          mdls -raw -name kMDItemFonts ~/Library/Fonts/machtgth.ttf +
                                          mdls -raw -name kMDItemFonts ~/Library/Fonts/machtssr-gm.ttf)
                                          (
                                          Momo,
                                          Regular
                                          )(
                                          HamiltonSteel,
                                          Regular,
                                          Trek,
                                          "Trek DS9 Credits Text"
                                          )(
                                          "Machine Tool Gothic",
                                          MachineToolGothic,
                                          Regular
                                          )(
                                          "Machine Tool SanSerif",
                                          MachineToolSanSerif,
                                          Regular
                                          )`

                                          learn from the mistakes of others, you may not live long enough to make them all yourself...

                                          1 Reply Last reply Reply Quote 0
                                          • D Offline
                                            driven
                                            last edited by

                                            getting closer, but I really don't know ruby, take lots of trial and error,
                                            > a=(find ~/Library/Fonts/*.ttf).to_a b=(a.collect{|x| mdls -raw -name com_apple_ats_name_family #{x}}) ["(\n Momo\n)", "(\n Trek\n)", "(\n \"Machine Tool Gothic\"\n)", "(\n \"Machine Tool SanSerif\"\n)"]how do I clean out the rest?

                                            learn from the mistakes of others, you may not live long enough to make them all yourself...

                                            1 Reply Last reply Reply Quote 0
                                            • 1
                                            • 2
                                            • 3
                                            • 4
                                            • 5
                                            • 6
                                            • 3 / 6
                                            • First post
                                              Last post
                                            Buy SketchPlus
                                            Buy SUbD
                                            Buy WrapR
                                            Buy eBook
                                            Buy Modelur
                                            Buy Vertex Tools
                                            Buy SketchCuisine
                                            Buy FormFonts

                                            Advertisement