Menu

Scripting

Konrad Twardowski
Attachments
Action Properties.png (10600 bytes)
Add Action.png (7176 bytes)

Custom Tool Bar Actions

Creating a new action

  1. Right-click on an empty tool bar area
  2. Select New Action...
    • Optionally select icon, enter a short name, and description
    • Select a script language you want to use (Note: currently only JavaScript is fully supported)
    • Click Create - a built-in Script Editor will appear where you can edit and test your script
  3. Right-click on the new action button again to change its properties

Using the built-in Script Editor

  1. Type a JavaScript code (Tip: Use Snippets menu to paste useful code samples)
  2. Click Test (F9) to compile and test the code
  3. Click Save to save changes and close editor

Examples

Auto search for a movie title using imdb.org

May be useful in Feed Viewer...

:::javascript
var Tabs = Java.type("org.makagiga.Tabs");
var MApplication = Java.type("org.makagiga.commons.MApplication");

var tab = Tabs.getInstance().selectedTab;
var title = tab.metaInfo.toString();
MApplication.openURI("http://www.imdb.com/find?s=all&q={0}", [title]);

Convert selected text to lower case

Works with Notepad editor...

:::javascript
var MStatusBar = Java.type("org.makagiga.commons.swing.MStatusBar");
var Editor = Java.type("org.makagiga.editors.Editor");

var core = Editor.currentCore;
if (core instanceof javax.swing.text.JTextComponent) {
    var text = core.selectedText;
    if (text) {
        core.replaceSelection(text.toLowerCase());
    }
    else {
        MStatusBar.info("No text selection");
    }
}

Hide menu bar and sidebar

:::javascript
var MainWindow = Java.type("org.makagiga.MainWindow");

var mainWindow = MainWindow.getInstance();
var menuBar = mainWindow.getJMenuBar();

var maximizeView = menuBar.minimized;
menuBar.minimized = !maximizeView;
mainWindow.getElementById("main-split-pane").sidebarVisible = maximizeView;

Change editor colors

Works with Notepad editor...

:::javascript
var Color = Java.type("java.awt.Color");
var MText = Java.type("org.makagiga.commons.swing.MText");
var Editor = Java.type("org.makagiga.editors.Editor");
var NotepadEditorCore = Java.type("org.makagiga.editors.notepad.NotepadEditorCore");

var notepad = Editor.currentCore; // get active editor/tab
if (notepad instanceof NotepadEditorCore && notepad.editable) {
    // set colors
    MText.setStandardColors(
        notepad,
        Color.BLACK, // background
        new Color(0x66cc00), // text
        true // animation
    );
    // set monospaced font
    notepad.style = "font-family: monospace";
}

User Script (user.js)

User Script is a simple JavaScript file automatically executed on application startup.

You can create/modify this file directly in Makagiga using the built-in script editor:

  1. Click menu -> Tools -> Console
  2. Type: script -u

The default user.js file location is:

[Makagiga profile folder]/scripts/user.js
Example: /home/username/.makagiga/scripts/user.js

See menu -> Help -> About -> System to display the Makagiga profile folder.

Related Documentation

Porting

From Rhino (Java 6/7) to Nashorn (Java 8)

Old Code

:::javascript
importClass(java.awt.Color) // ERROR: "importClass" is not defined
// ...
println("Foo") // ERROR: "println" is not defined

New Code

:::javascript
var Color = Java.type("java.awt.Color")
// ...
print("Foo")

See Also


Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.