Open web page in After Effects with ExtendScript

大城市里の小女人 提交于 2019-12-09 07:16:29

问题


This may be a simple one but I can't figure it out. How can I open a web page in the main browser from extendscript as I would do with window.open() in Javascript?

I am targeting After Effects and would like it to work on both OS X and Windows.


回答1:


In After Effects you can simply do it using the system object, as Dirk mentioned. However you need several things for that:

  • checking that the script can access the network:

    if (app.preferences.getPrefAsLong("Main Pref Section", "Pref_SCRIPTING_FILE_NETWORK_SECURITY") != 1)
    {
        alert("Please tick the \"Allow Scripts to Write Files and Access Network\" checkbox if Preferences > General");
    
        // Then open Preferences > General to let people tick the checkbox
        app.executeCommand(2359);
    
        // Here you should check again if they ticked it, and choose to continue or stop ...
    }
    
  • checking of the OS:

    var os = system.osName;
    if (!os.length)
    {
        // I never remember which one is available, but I think $.os always is, you'll have to check
        os = $.os;
    }
    app_os =  ( os.indexOf("Win") != -1 )  ?  "Win" : "Mac"
    
  • os-dependent system calls:

    var url = "http://aescripts.com";
    
    if ( app_os == "Win" )
    {
        system.callSystem("explorer " + url);
    }
    else
    {
        system.callSystem("open " + url);
    }
    



回答2:


One application independent way is to write an operating system's representation of the URL into a file, then execute() the file.

On the Mac that would be a .webloc file. The underlying format is "plist binary", if you prefer to generate xml, create a sample webloc by drag&drop from the browser address and convert it:

plutil -convert xml1 ~/Desktop/sample.webloc

To invoke that webloc, run the ExtendScript

File("~/Desktop/sample.webloc").execute()



回答3:


You can do anything on your local computer - commandline and anything else in a VBS file, and you can launch a vbs file from javascript like this:

function RunScriptVBS(whatscriptname){
    app.doScript(File(whatscriptname), ScriptLanguage.VISUAL_BASIC);
}

Here is your vbs script:

Dim objShell
Set objShell = CreateObject("WScript.shell")
objShell.Run ("http://www.somewhere.com")
set objShell = nothing



回答4:


The scope of the question apparently has been refined to After Effects (AE), so I add another answer specific to that application.

On my Machine AE CS6 does not produce an object model file for display by the ExtendScript Toolkit. Please retry it yourself, the object model viewer is in the help menu of ESTK.

Anyway, the ESTK data browser does works. If you target AE, you'll see a couple of objects and classes. Eventually check some more menu items in the databrowser panel flyout menu. I had a deeper look at the app object itself (no openUrl() there) and also found a "system" object. Expand that and you see several interesting methods.

The following script opens a URL on the Mac. I have not tried Windows, maybe it is even the same.

system.callSystem("open http://www.google.com")

As this is the first time I launched AfterEffects, I might have missed better ways.




回答5:


Provided you have access to CSInterface.js:

cep.util.openURLInDefaultBrowser("http://www.google.com")


来源:https://stackoverflow.com/questions/17665920/open-web-page-in-after-effects-with-extendscript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!