5
$\begingroup$

I have Mathematica 8 on my PC. I also have a new Mac with CDF-player, but not Mathematica. I want a Tooltip that shows one thing if running on a PC, and something different if running on a Mac. Both of the following show "MS-Windows" in the Tooltip even when using my Mac.

Tooltip["A String",
If[StringMatchQ[$Version,__~~"Windows"~~__],"MS-Windows",(* else Mac *)"Probably OS X"]
]

Tooltip["A String",
If[SystemInformation["FrontEnd","MachineType"]==="PC","MS-Windows",(* else Mac *)"Probably OS X"]
]

It will be even better if it can hande a third case where the OS is neither Windows or OS X. Can you show me how to do it?

$\endgroup$
9
$\begingroup$

I don't think the answer is related to choosing $OperatingSystem or SystemInformation as in Mr.Wizard's and F'x's answers (although both are cleaner than using $Version). I'm guessing you created your file on your PC and then opened it in your Mac. Tooltip then shows you the cached result from your PC. To make the tooltip refresh on your other machines, simply make it a Dynamic one. I would do:

Dynamic@Tooltip["A String", $OperatingSystem]
$\endgroup$
5
$\begingroup$

How about using $OperatingSystem?

Typical values for $OperatingSystem are "Windows", "MacOSX" and "Unix".

$OperatingSystem
"Windows"
$\endgroup$
  • $\begingroup$ This is the best criteria to use. However, failure to use Dynamic (See RM's solution) is real cause of my problem. $\endgroup$ – Ted Ersek Aug 28 '12 at 8:59
3
$\begingroup$

What if you try using SystemInformation["Kernel", "OperatingSystem"] instead of matching $Version? On my Mac, I get:

In[1]:= SystemInformation["Kernel", "OperatingSystem"]
Out[1]= "MacOSX"
$\endgroup$
  • $\begingroup$ I undid my vote for this answer as I don't know if there is any advantage to this over $OperatingSystem -- if there is I will gladly restore my vote. $\endgroup$ – Mr.Wizard Aug 26 '12 at 22:58
  • 3
    $\begingroup$ @Mr.Wizard I presume if you connect to a remote kernel, the answer will be different. $\endgroup$ – rm -rf Aug 27 '12 at 1:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.