22
$\begingroup$

Within a Mathematica program with a graphical user interface I want to programmatically determine whether the code runs in a full Mathematica, a Player Pro or a CDF-Player. There seem to not be any documented functions which would allow to get that information. I understand that this might be on purpose, as the idea is that it shouldn't matter. At least Mathematica Player Pro provides basically the same functionality as Mathematica. But there are some subtle differences and of course the CDFPlayer has well known limitations.

For the moment I have ways to get that information, but they are all somewhat dirty and/or not very reliable:

  • Look at variables like $InstallationDirectory or $BaseDirectory and check for known directory names
  • Look at SystemInformation[] or Options[$FrontEnd] and use heuristics to get the desired information from what these return.
  • try something that is known to not work with CDF Player (e.g. export data). Will of course not work for a Player Pro.

and of course one could use any combination of these things to get a more reliable result.

Does anyone know a better way to get that information?

$\endgroup$
9
  • $\begingroup$ Is this what you are looking for? official comparison $\endgroup$ Commented Nov 6, 2012 at 17:06
  • $\begingroup$ @VitaliyKaurov I think it is about getting info on the environment the code is running in (i.e. Mathematica, Player etc.) $\endgroup$
    – Yves Klett
    Commented Nov 6, 2012 at 17:12
  • 10
    $\begingroup$ Perhaps try $LicenseType ("Professional" for Mathematica; presumably something else for Player) or the supposedly (but not really) deprecated $ProductInformation (gives "ProductIDName" -> "Mathematica" vs. "ProductIDName" -> "MathematicaPlayer"). For the CDF plugin you can check CurrentValue[PluginEnabled]. $\endgroup$ Commented Nov 6, 2012 at 17:13
  • 1
    $\begingroup$ Oh, and if you want to figure out if you're running in the plugin/Player sandbox, you can use Developer`$ProtectedMode for that too. $\endgroup$ Commented Nov 6, 2012 at 17:36
  • 1
    $\begingroup$ @Ajasja because all of this is undocumented and I don't have the Player installed or the time to test it properly. Whoever does and can state definitively what the results will be in various situations and for different versions of the relevant products is welcome to use my suggestions in their own answer if they wish. $\endgroup$ Commented Nov 6, 2012 at 19:37

3 Answers 3

18
$\begingroup$

The straightforward way to discriminate is to use $LicenseType, (unfortunately undocumented and not even WolframLanguageData knows about it). Deploying the following line as a CDF file and opening it in various environments provides the following results (thanks for Oleksandr's comment):

Dynamic@{$LicenseType, Developer`$ProtectedMode, CurrentValue["PluginEnabled"]}

(* Mathematica 8-10 *)           {"Professional", False, False}
(* CDF Player *)                 {"Player", False, False}
(* Firefox w/ browser plugin *)  {"Professional", True, True}
(* Player Pro *)                 {"Player Pro", False, False}

For more on $LicenseType, see other thread.


As of version 10, one can also use $EvaluationEnvironment, answering a different, but related question. It returns one of the followings:

"Session"          local interactive session
"RemoteSession"    remote interactive session
"CDF"              standalone CDF
"Script"           script run in batch mode
"Subkernel"        parallel or grid subkernel
"WebEvaluation"    direct URL evaluation
"WebLoad"          evaluation when loading a webpage
"WebAPI"           API called through an HTTP request
"WebForm"          web form
"WebServer"        web server plugin (e.g. JSP)
"CloudCDF"         cloud CDF
"PlugInCDF"        CDF web plugin
"Scheduled"        scheduled task
"WolframLink"      WolframLink call

Please feel free to add to the lists if you know other licenses/environments.

$\endgroup$
8
  • $\begingroup$ Thanks for helping to flesh this out into a useful answer. Another thing I had been wondering is what $LicenseType is for Mathematica for Students or the Home Edition? I don't have either of these products so I can't easily check, but perhaps someone else can fill in the additional details? $\endgroup$ Commented Nov 7, 2012 at 8:37
  • $\begingroup$ Great stuff here, I should browse your answer more carefully :P $\endgroup$
    – Kuba
    Commented Mar 27, 2014 at 14:18
  • $\begingroup$ Thanks @Kuba; in this case I've just found out about $EvaluationEnvironment while browsing the non-final documentation online. Many things are revealed from weak to weak as they are getting closer to roll out the new version. $\endgroup$ Commented Mar 27, 2014 at 14:59
  • $\begingroup$ I still think that your answer correctly answers my question, but in the current form it isn't very clear as the description of $EvaluationEnvironment is too prominent (IMO), considering in the "final" implementation seems to be a solution to a different while related problem. I would consider the use of $LicenseType is the answer to my question as it was stated. As $EvaluationEnvironment is of course also interesting, I wouldn't want that to be removed, but I'd suggest to probably make more clear that it actually is $LicenseType which answers the question. $\endgroup$ Commented Jun 8, 2016 at 8:26
  • $\begingroup$ @Albert Done. I'm quite disappointed that I couldn't figure out more about $LicenseType though. Perhaps someone else. $\endgroup$ Commented Jun 8, 2016 at 9:49
10
$\begingroup$

The following

MathLink`CallFrontEnd@FrontEnd`Value["$NotebookLicenseType"]

will distinguish "Player Pro" from just "Player", or Mathematica, which the other methods do not handle if you need to make such a distinction.

$\endgroup$
1
  • 1
    $\begingroup$ In Wolfram CDF Player Version 10 this gives "Professional". $\endgroup$ Commented Feb 19, 2015 at 20:09
5
$\begingroup$

These are undocumented, but I doubt they will change much going forward... I think they are available in v9 or later, but I don't recall exactly when they were introduced...

FE`Evaluate@FEPrivate`PlayerQ[]
FE`Evaluate@FEPrivate`PlayerProQ[]

FEPrivate`PlayerQ[] returns True when the document is running in CDF Player mode. FEPrivate`PlayerProQ[] returns True when the document is an EnterpriseCDF or is running inside of an activated copy of CDF Player.

If you use them inside of a Dynamic, you probably would not need to use the FE`Evaluate wrapper.

$\endgroup$
1
  • $\begingroup$ thanks, great finding. As none of the other solutions are documented I think this is just as good as any of them. I'll try to experiment with that to learn whether it fits my purposes as good or better than the other possibilities... $\endgroup$ Commented Jun 8, 2016 at 16:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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