I suspect I inadvertently flagged my own post as inappropriate. Please reverse that out.
Link to post:
(How to access System Preferences in JSL, specifically the date format setting)
by SteveTerry
https://community.jmp.com/t5/Discussions/How-to-access-System-Preferences-in-JSL-specifically-the-date/m-p/280619#M54365
<p>I've searched around and haven't found any simple way to get System Preferences settings from within JSL. I'm developing on a Mac – (JMP 14 & 15) – but would also like to know how to do this on Windows. The closest I got was a <a href="https://community.jmp.com/t5/Discussions/Manage-the-display-language-with-JSL-or-freezing-english/td-p/236566" target="_self">discussion</a> on how to get the language code:</p><p> </p><pre><code class=" language-jsl">System Service( Get Language Code );</code></pre><p><code class=" language-jsl">System Service</code> sounds like and interesting function, but I couldn't find any documentation on it. I'm looking for a general solution but am immediately interested in finding the date format, (per setting in System Preferences ➔ Language & Region ➔ Advanced... ➔ Dates ➔ Short), as shown below:</p><p> </p><p><li-image width="419" height="304" alt="Screen Shot 2020-07-20 at 5.55.13 PM.png" align="inline" id="25579iA7A4C74EE827C951" size="large" resized="true" sourcetype="new"></li-image></p><p>The <em>Short</em> date delimiters are normally set to slashes by default, but were modified by me to dashes in the image above. The specific issue I find with changing this setting is that it affects what arguments are valid to the <code class=" language-jsl">Input Format</code> function. For example, the following statement will generate a runtime error:</p><p> </p><pre><code class=" language-jsl">col << Input Format( "y/m/d h:m:s" );</code></pre><p>So the code must instead look like:</p><pre><code class=" language-jsl">col << Input Format( "y-m-d h:m:s" );</code></pre><p>And the reverse it true if the user has their System Preferences set to slashes. Furthermore, with the <code class=" language-jsl">Format</code> function, if the wrong date string is given, there won't be a runtime error, but the relevant datetime column will ignore the format setting, and the data will be left in its raw, unintelligible form.</p><p> </p><p>Thus, the set of valid arguments are dependent on the user's setting, and the code must first read this setting to determine which format to use.</p><p> </p><p>As a workaround, I was able to collect the settings information from a system Unix command and parse it accordingly:</p><p> </p><pre><code class=" language-jsl">// implement Unix command:
// $ defaults read com.apple.mail DateCellWidthCache | grep M.d.yy
Clear Log();
// read System Preferences from 'defaults' that contains date format string.
sDefaults = Run Program(
Executable( "/usr/bin/defaults" ),
Options( { "read", "com.apple.mail", "DateCellWidthCache" } ),
Read Function( "text" )
);
//Write( sDefaults );
ss1 = Munger( sDefaults, 1, "M/d/yy" ); // check for slash style.
ss2 = Munger( sDefaults, 1, "M-d-yy" ); // check for dash style.
Show( ss1, ss2 ); Write("\!n");
If( ss1 > 0,
Write( "Using slashes.\!n");
,
/* else if */ ss2 > 0,
Write( "Using dashes.\!n");
,
/* else */
Write( "***ERROR: unrecognized date delimiter.\!n");
Write( "defaults read com.apple.mail DateCellWidthCache:\!n");
Write( sDefaults );
);</code></pre><p>However, this seems a bit clumsy, and I imagine there's a simpler way. It's apparent that the JMP engine can read this setting as it presents a very different set of time formats in the Column Properties dialog based on this setting, as shown below (presenting only the dash options here):</p><p> </p><p><li-image width="362" height="597" alt="Screen Shot 2020-07-20 at 6.30.49 PM.png" align="inline" id="25580i8912953604D384AD" size="large" resized="true" sourcetype="new"></li-image></p><p>So, my question is: Is there a simple way to get arbitrary System Preferences values (and the date format specifically) by using <code class=" language-jsl">System Service</code> or some other function?</p><p> </p>
This message has 0 replies