zimlet change url if it is a file link than correct link or start external program

127 views Asked by At

I have a problem in browser with sent file links:

file:/// instead of file:// and i would like to create a zimlet which is check links in mail and if it is a file link then change file:/// to file:// and start on click.

Or start external program if it is a file link. I created the link reader program but i don't know how to start it or implement to a zimlet. Do you have any idea? thanks in advance for any help. My example for link correction in .net but how it looks like in java ajax:

 foreach (string b in args)
            {


                //  Console.WriteLine(b);
               if (b.Contains("file:F"))
                {
                     string d = b.Replace(@"file:F", @"F");
                     System.Diagnostics.Process.Start(d);
                }
          else if (b.Contains("file:///F:"))
               {
                   string d = b.Replace(@"file:///F:", @"F:");
                   System.Diagnostics.Process.Start(d);
               }

}

Here the string is readed and checked and replaced with good starting chars. I think it have to work in java too but i am not good in java.

Please Help!

I tried with converter: But it not works:

try
    {
        for (String b : args)
        {


            //  Console.WriteLine(b);
           if (b.contains("file:F"))
           {
                 String d = b.replace("file:F", "F");
                 System.Diagnostics.Process.Start(d);
           }

           else if (b.contains("file:///F:"))
           {
               String d = b.replace("file:///F:", "F:");
               System.Diagnostics.Process.Start(d);
           }

           else
           {
               System.out.println("File Not Contain Valid File Link!");
               System.out.println("Or File Missing!");
               Console.ReadKey();
           }
            // Console.WriteLine(d);
            //  Console.ReadKey();
          //  System.Diagnostics.Process.Start(d);
        }
    }
    catch (RuntimeException e)
    {


        System.out.println("File Not Contain Valid File Link!");
        System.out.println("Or File Missing!");
        Console.ReadKey();


    }

I have a new idea! How can i run links automatically in new tab? Like if i click on a link than automatically open new tab and copy url to there and run. It have to be an right-click menu i think. It should work.

UPDATE: Now i using an example: for right click menu now it is working on click pop up message:

// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// The onClicked callback function.
function onClickHandler(info, tab) {
  if (info.menuItemId == "radio1" || info.menuItemId == "radio2") {
    console.log("radio item " + info.menuItemId +
                " was clicked (previous checked state was "  +
                info.wasChecked + ")");
  } else if (info.menuItemId == "checkbox1" || info.menuItemId == "checkbox2") {
    console.log(JSON.stringify(info));
    console.log("checkbox item " + info.menuItemId +
                " was clicked, state is now: " + info.checked +
                " (previous state was " + info.wasChecked + ")");

  } else {
    console.log("item " + info.menuItemId + " was clicked");
    console.log("info: " + JSON.stringify(info));
    console.log("tab: " + JSON.stringify(tab));
  }

Pop-up message is here

alert("I am an alert box!");
};

chrome.contextMenus.onClicked.addListener(onClickHandler);

// Set up context menu tree at install time.
chrome.runtime.onInstalled.addListener(function() {
  // Create one test item for each context type.
  var contexts = ["page","selection","link","editable","image","video",
                  "audio"];
  for (var i = 0; i < contexts.length; i++) {
    var context = contexts[i];
    var title = "Test '" + context + "' menu item";
    var id = chrome.contextMenus.create({"title": title, "contexts":[context],
                                         "id": "context" + context});
    console.log("'" + context + "' item:" + id);
  }

  // Create a parent item and two children.
  chrome.contextMenus.create({"title": "Test parent item", "id": "parent"});
  chrome.contextMenus.create(
      {"title": "Child 1", "parentId": "parent", "id": "child1"});
  chrome.contextMenus.create(
      {"title": "Child 2", "parentId": "parent", "id": "child2"});
  console.log("parent child1 child2");

  // Create some radio items.
  chrome.contextMenus.create({"title": "Radio 1", "type": "radio",
                              "id": "radio1"});
  chrome.contextMenus.create({"title": "Radio 2", "type": "radio",
                              "id": "radio2"});
  console.log("radio1 radio2");

  // Create some checkbox items.
  chrome.contextMenus.create(
      {"title": "Checkbox1", "type": "checkbox", "id": "checkbox1"});
  chrome.contextMenus.create(
      {"title": "Checkbox2", "type": "checkbox", "id": "checkbox2"});
  console.log("checkbox1 checkbox2");

  // Intentionally create an invalid item, to show off error checking in the
  // create callback.
  console.log("About to try creating an invalid item - an error about " +
      "duplicate item child1 should show up");
  chrome.contextMenus.create({"title": "Oops", "id": "child1"}, function() {
    if (chrome.extension.lastError) {
      console.log("Got expected error: " + chrome.extension.lastError.message);
    }
  });
});

And i created a hta file which is running my exe:

<script type="text/javascript" language="javascript">
var oShell = new ActiveXObject("Shell.Application");
var commandtoRun = "F:\\ABLAGE\\link_reader_ip.exe"; 
oShell.ShellExecute(commandtoRun,"","","open","1");
</script>

New problems: 1. How to start on click hta file:

function callShellApplication(){
var objShell = new ActiveXObject("WScript.shell");
objShell.Run('"d:\\test.hta"');
}

no error , but the test.hta file wont start.

  1. if the hta run my file it opens an extra window but i wont.

Please someone help me.

0

There are 0 answers