Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question

3 Answers 3

up vote 9 down vote accepted

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]
share|improve this answer

How about using $OperatingSystem?

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

$OperatingSystem
"Windows"
share|improve this answer
    
This is the best criteria to use. However, failure to use Dynamic (See RM's solution) is real cause of my problem. –  Ted Ersek Aug 28 '12 at 8:59

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"
share|improve this answer
    
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. –  Mr.Wizard Aug 26 '12 at 22:58
3  
@Mr.Wizard I presume if you connect to a remote kernel, the answer will be different. –  rm -rf Aug 27 '12 at 1:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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