ue-js脚本学习1

演示脚本
hello.js 脚本演示了支持脚本最简单的格式——写入活动文件的单行脚本:
// Hello!  Welcome to the UltraEdit scripting environment.  Normally, you would
// put a header comment at the top of a javascript file to be used in UltraEdit
// in order to indicate the version of the UltraEdit scripting API, like so:
// Version = 1.00
// However, this is currently not necessary since the API will default to 1.00.

// ----------------------------------------------------------------------------
// hello.js
// A basic javascript to introduce our users to embedded scripting support in
// UltraEdit v13.00!
// Copyright (c)2007 IDM Computer Solutions, Inc.
// ----------------------------------------------------------------------------
// UltraEdit is our application object.  All UltraEdit operations will use this
// object.
// Operations may be performed on the activeDocument property of the UltraEdit
// object.
// See UltraEdit Help for more details.

//Create a new file, which will become the currently active document
UltraEdit.newFile();
//write the string "Hello World" to the currently active document
UltraEdit.activeDocument.write("Hello World!");
要调用该脚本,请转到高级菜单中的脚本并点击子菜单中的脚本...条目。 将显示脚本配置对话框。 如果按添加按钮并导航至安装目录下的“scripts”目录,则可以将“hello.js”添加到可以运行的脚本列表中。 您可以通过点击“热键”字段并按所需的键来指定脚本的快捷键。 添加的脚本将在以上提到的脚本...子菜单底部动态更新,且可以通过热键或点击列表中的脚本名称进行调用。
为了完全独立运行,该脚本实际上创建了一个新的编辑文档进行编写,且该脚本可以在不打开任何文档的情况下运行。
stringvar.js 脚本显示了该脚本可以抓取用户的输入并将其存储在变量中以便将来使用:
// Hello!  Welcome to the UltraEdit scripting environment.  Normally, you would
// put a header comment at the top of a javascript file to be used in UltraEdit
// in order to indicate the version of the UltraEdit scripting API, like so:
// Version = 1.00
// However, this is currently not necessary since the API will default to 1.00.

// ----------------------------------------------------------------------------
// stringvar.js
// This script queries the user for a string which will be used in a find 
// operation and a value that determines how many times the operation should
// occur.  A new file will be created for the results.  For each word found,
// the entire line will be selected, copied, and written to the result file.
// Copyright (c)2007 IDM Computer Solutions, Inc.
// ----------------------------------------------------------------------------
// UltraEdit is our application object.  All UltraEdit operations will use this
// object.
// See UltraEdit Help for more details.

// Get user input.
var num = UltraEdit.getValue("How many occurrences do you want to find?",2);
var str = UltraEdit.getString("What string do you want to find?",1);

// Create new file.  This will also become the active file.
UltraEdit.newFile();

UltraEdit.document[0].top();
// Do operation number of requested iterations.
var x = 0;
while (x < num) {
  UltraEdit.document[0].findReplace.find(str);
  UltraEdit.document[0].selectLine();
  UltraEdit.document[0].copy();
  if (UltraEdit.document[0].isFound() == true) {
    UltraEdit.activeDocument.paste();
  }
  x++;
}
该脚本可以像上述 hello.js 脚本一样进行调用。 要运行本演示,请打开任意文本文件并指定要搜索的字符串,以及希望查找到的次数。 该脚本随后将打开新的文档,并将匹配行的指定数量写入新文件。

header.js 脚本演示了使用 document JavaScript 阵列对象(UltraEdit 应用程序对象的属性之一)查找打开文件个数的功能 。  这是所有当前同时打开文档的阵列。 UltraEdit 是全部 UltraEdit 操作所基于的应用程序对象。 使用该信息,脚本将在所有打开的文档中重复写入预定义的标题:
// Hello!  Welcome to the UltraEdit scripting environment.  Normally, you would
// put a header comment at the top of a javascript file to be used in UltraEdit
// in order to indicate the version of the UltraEdit scripting API, like so:
// Version = 1.00
// However, this is currently not necessary since the API will default to 1.00.

// ----------------------------------------------------------------------------
// header.js
// This script creates a header for all open documents
// Copyright (c)2007 IDM Computer Solutions, Inc.
// ----------------------------------------------------------------------------
// UltraEdit is our application object.  All UltraEdit operations will use this
// object.
// See UltraEdit Help for more details.

// Get the num of open documents.
var num_of_docs = UltraEdit.document.length;

var dashes = "// ------------------------------------------------------------";
dashes += "----------------\r\n";

// Enumerate through all open documents and add the header.
var index;
for (index = 0; index < num_of_docs; index++) {
  UltraEdit.document[index].top();
  UltraEdit.document[index].write(dashes);
  UltraEdit.document[index].write("// Script Name: \r\n");
  UltraEdit.document[index].write("// Creation Date: \r\n");
  UltraEdit.document[index].write("// Last Modified: \r\n");
  UltraEdit.document[index].write("// Copyright (c)2007\r\n");
  UltraEdit.document[index].write("// Purpose: \r\n");
  UltraEdit.document[index].write(dashes);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值