|
|
MortScript まとめ&マニュアル要訳by MortScriptスレの111/14/09 更新 2スレ目のdatをUPしました。 業務連絡はこちらへ。 スクリプティングに関する個別の質問などには対応出来ませんので、MortScriptスレへどうぞ。 |
Message( "This is ¥
a test" )Message( "Hallo" ) ※原文ママ。ドイツの人はこう綴るらしいです。Sleep( 500 )Sleep( pause * 100 )Message( "Battery level: " & BatteryPercentage() & "%" )message = "Battery level: " & BatteryPercentage() & "%"If ( BatteryPercentage() > 20 )
# 命令文
EndIfMessage( "He said: ""This is a test""" )myvar = 5 * x + yLocal()
x = "Test"
Call( "Sub1" )
Call( "Sub2" )
Message( x ) …「Test」を表示。ローカル変数「x」はサブルーチン内で変更されないので。Message( y ) …空文字列を表示。「y」というローカル変数は無いので(グローバル変数のみ。下記を見よ)Sub Sub1
x = 5 …グローバル変数「x」を定義
Local( x )
y = "Hi!" …グローバル変数!(「x」のみがローカル)
Message( x ) …空文字列を表示(ローカル変数「x」は未定義なので)
EndSub
Sub Sub2
Global( x )
Message( x ) …グローバル値「5」を表示。
Message( y ) …空文字列を表示。「y」というローカル変数は無いので。
EndSub
ForEach key, value in iniKeys ( iniFile, section )
array[key] = value
EndForEacharray[ 3 ] = "c"
Message( array[ 1 + 2 ] )
day[1][1] = "Mon"
day[1][2] = "Tue"
day[1][3] = "Wed"
day[2][1] = "Thu"
day[2][2] = "Fri"
day[2][3] = "Sat"
x = Choice( "Selection", "Choose something", 0, 0, day[2] )
day[2007][1][1] = "Mon"
day[2007][1][2] = "Tue"
day[2007][1][3] = "Wed"
day[2008][2][1] = "Fri"
day[2008][2][2] = "Sat"
day[2008][2][3] = "Sun"
x = Choice( "Selection", "Choose something", 0, 0, day[2008][2] )array[ "1" & 1 ] = "eleven"
Message( array[ (2-1) & "1" ] )
list[1] = "a"
list[2] = "b"
list[5] = "f"
list["a"] = "A"
idx = Choice( "Selection", "Choose something", 0, 0, list )
→「a」と「b」だけが Choice ダイアログに表示される。
[targetVar] = [sourceVar] * 10
Choice( "Selection", "Select:", [choiceArrayName] )
GetTime( [varHour], [varMinute], [varSecond] )
i = 1
month_en = "January"
month_jp = "1月"
lang = "en"
["month_" & i] = ["month_" & lang]
Message( month_1) →「January」を表示
lang = "jp"
["month_" & i] = ["month_" & lang]
Message( month_1) →「1月」を表示 ( ) : 括弧 NOT : 否定 ^ : 累乗(x^y = xy) * / MOD : 乗算、除算、除算の余り + - : 加算、減算 & ¥ : 文字列の連結 > >= < <= = <> : 数の比較 gt ge lt le eq ne : 文字列の比較 条件文 ? 真の場合の値 : 偽の場合の値# x の値を自由に設定してみてください
x = -2
y = ( x > 0 ? x : x*-1 )
Message( y ) AND && : 論理積「and」 OR || : 論理和「or」"¥My Documents¥" ¥ "¥file.txt"
"¥My Documents" ¥ "file.txt"
"¥My Documents¥" ¥ "file.txt""¥My Documents¥" & "¥file.txt""¥My Documents" & "file.txt""¥My Documents¥" & "file.txt" If ( wndExists( "Word" ) )
EndIf
While ( x <> 5 )
EndWhile
If ( 式 )
{ 命令文 }
{ ElseIf( 式 )
{ 命令文 } }
[ Else
{ 命令文 } ]
EndIfSwitch ( 式 )
Case ( 値 {, 値 } )
{ 命令文 }
{ Case ( 値 {, 値 } )
{ 命令文 } }
EndSwitch#月を自由に設定してみて下さい
m = 3
Switch( m )
Case( 3, 4, 5 )
Season = "春"
Case( 6, 7, 8 )
Season = "夏"
Case( 9, 10, 11)
Season = "秋"
Case( 12, 1, 2 )
Season = "冬"
Case( 1, 3, 5, 7, 8, 10, 12 )
MonthL = "大の月"
Case( 2, 4, 6, 9, 11 )
MonthL = "小の月"
EndSwitch
Message( Season & ", " & MonthL )#月を自由に設定してみて下さい
m = 3
Switch( 1 )
Case( m < 4 )
fYear = "旧年度"
Case( m >= 4 )
fYear = "新年度"
EndSwitch
Message( fYear )( Choice( タイトル, プロンプト, 値, 値 {, 値 } )
| Choice( タイトル, プロンプト, 配列 )
| ChoiceDefault( タイトル, プロンプト, デフォルト, タイムアウト, 値, 値 {, 値 } )
| ChoiceDefault( タイトル, プロンプト, デフォルト, タイムアウト, 配列 )
)
Case( 値 {, 値 } )
{ 命令文 }
{ Case( 値 {, 値 } )
{ 命令文 } }
EndChoice
Choice( "Test", "Select a number", "One", "Two", "Three" )
Case( 1 )
Message( "One" )
Case( 2, 3 )
Message( "Two of three" )
Case( 3 )
Message( "Three" )
Case( 0 )
Message( "Cancel" )
Exit
EndChoiceWhile( 条件 )
{ 命令文 }
EndWhileForEach 変数 {, 変数 } in タイプ ( 引数 {, 引数 } )
{ 命令文 }
EndForEach#配列「array」に3つの要素を代入しようとして
i = 1
ForEach array[i] in values ( "one", "two", "three" )
i = i + 1
EndForEach
#↑こうしても、
Message( array[1] & ", " & array[2] & ", " & array[3] )
#→「three, , 」としか表示されません。
#↓こうすれば大丈夫
i = 1
ForEach var in values ( "one", "two", "three" )
array[i] = var
i = i + 1
EndForEach
Message( array[1] & ", " & array[2] & ", " & array[3] )
#→「one, two, three」と期待通りに表示されます。ForEach 変数 in values ( 値 {, 値} )ForEach 変数 in array ( 配列 )ForEach key, value in array ( 配列 )ForEach 変数 in split ( 値, デリミタ, トリム? )ForEach 変数 in charsOf ( 文字列 )ForEach 変数 in iniSections ( INIファイル )ForEach key, value in iniKeys ( INIファイル , セクション )ForEach 変数 in regSubkeys ( ルート, キー )ForEach value, data in regValues ( ルート, キー )ForEach 変数 in files ( 検索式 )ForEach 変数 in directories ( 検索式 )Repeat( カウント数 )
{ 命令文 }
EndRepeatFor 変数 = start to end [ step step ]
{ 命令文 }
Next
For( $i = 1; $i <= 10; $i++ ){
#命令文
}
For i = 1 to 10 step 1
#命令文
Next
Sub サブルーチン名
{ 命令文 }
EndSubCall( サブルーチン名 {, 引数 } )
CallFunction( サブルーチン名, 変数 {, 引数 } )Include( MortScriptファイル )
CallScript( MortScriptファイル {, 引数 } )
CallScriptFunction( MortScriptファイル, 変数 {, 引数 } )
CallScript( "subscript.mscr" )Return( 値 )ExitErrorLevel( エラーレベル )変数 = 式変数 += 式変数 -= 式変数 *= 式変数 /= 式変数 &= 式変数 \= 式Set( 変数, 式 )GrandMother = "Mother"
Set( %GrandMother%, "Daughter")
Message( Mother )GrandMother = "%Mother%"
Mother = "Daughter"
Set( %GrandMother%, "GrandDaughter")
Message( Daughter )value = Eval( 文字列 )x = Eval( "1+5*x" )Clear( 変数 )bool = IsEmpty( 変数 )Local( [ 変数 {, 変数 } ] )
Global( 変数 {, 変数 } )
int = Length( 文字列 )x = Length( "This is a test" )string = SubStr( 文字列 , 開始インデックス [, 長さ ] )x = SubStr( "abcder", 2, 3 )x = SubStr( "asdf", -3 )string = CharAt( 文字列, 位置 )string = Part( 文字列 , デリミタ, インデックス [, トリム? ] )x = Part( "a | b | c", "|", 2 )x = Part( "a¥ b ¥ c.def", "¥", -1, 0 )x = Part( "eins, zwei, drei", ",", 4 )int = Find( 検索対象文字列 , 検索文字列 [, 検索開始インデックス ])x = Find( "abcdefcd", "cd", 5 )x = Find( "abcdef", "CD" )int = ReverseFind( 検索対象文字列 , 検索文字 )x = ReverseFind( "abcba", "b" )string = Replace( 対象文字列, 検索文字列, 置換文字列 )x = Replace( "My old string", "old", "new" )string = ToUpper( 文字列 )
string = ToLower( 文字列 )x = "abc"
Message( ToUpper( x ))x = ToUpper( "Abcba" )x = ToLower( "AbcBA" )string = UcChar( 値 )
int = UcValue( 文字 )x = UcValue( "A" )c = UcChar( x + 1 )string = FilePath( ファイルパス )
string = FileBase( ファイルパス )
string = FileExt( ファイルパス )string = Format( 値, 小数桁 )x = Format( 123.456789, 2 )x = Format( 12, 2 )string = NumberToHex( 整数 )
int = HexToNumber( 文字列 )int/float = Round( 値[, 桁] )
int/float = Floor( 値[, 桁] )
int/float = Ceil( 値[, 桁] )int = Rand( max )
float = Rand( )float = Sin( ラジアン値 )
float = Cos( ラジアン値 )
float = Tan( ラジアン値 )
float = log( 値 )
float = log10( 値 )
float = Sqrt( 値 )
int = CompareFloat( 値1, 値2, 小数桁 )
value = Min( 値, 値{, 値 } )
value = Max( 値, 値{, 値 } )
int = MaxIndex( 配列 )
array[1]="a"
array["2"]="b"
array[3]="c"
array[5]="e"
array["x"]="X"
max = MaxIndex( array )
int = ElementCount( 配列 )配列 = Array( 値 {, 値 } )
days = Array( "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" )
day = days[ FormatTime("w")+1 ]
配列 = Map( インデックス, 値 {, インデックス, 値 } )
months = Map( "01", "Jan", "02", "Feb", "03", "Mar", etc. )
month = months[ FormatTime("m") ]
Split( 文字列 , デリミタ, トリム?, 変数{, 変数 })
配列 = Split( 文字列, デリミタ [, トリム? ] )
Split( "a | b | c", "|", 1, a, b, c, d )Split( "a¥ b ¥c.def", "¥", 0, a, b )Split( "one, two, three", ",", 1, list )list = Split( "one, two, three", "," )Run( アプリケーション[, 引数 ] )Run( "¥Windows¥スタート メニュー¥Messages.lnk" )Run( "¥Windows¥PWord.exe", "¥My Documents¥doc.psw" )RunWait( アプリケーション[, 引数 ] )CallScript( MortScriptファイル {, 引数 })
CallScriptFunction( MortScriptファイル {, 引数 })
New( メニューエントリー )New( "予定" )RunAt( Unix タイムスタンプ, アプリケーション[, 引数] )RunAt( 年, 月, 日, 時, 分, アプリケーション[, 引数] )RunAt( starttime, SystemPath( "ScriptExe" ) ¥ "MortScript.exe", ¥
"""" & SystemPath( "ScriptPath" ) ¥ "notify.mscr" & """" )RunOnPowerOn( アプリケーション[, 引数] )RemoveNotifications( アプリケーション[, 引数] )Show( ウィンドウタイトル )Minimize( ウィンドウタイトル )Close( ウィンドウタイトル )string = ActiveWindow()bool = WndActive( ウィンドウタイトル )bool = WndExists( ウィンドウタイトル )WaitFor( ウィンドウタイトル, 秒 )WaitForActive( ウィンドウタイトル, 秒 )string = WindowText( x, y )
GetWindowPos( ウィンドウタイトル, left, top, right, bottom )
int = WndLeft( ウィンドウタイトル )
int = WndRight( ウィンドウタイトル )
int = WndTop( ウィンドウタイトル )
int = WndBottom( ウィンドウタイトル )
SendOK [ ( ウィンドウタイトル ) ]SendCancel [ ( ウィンドウタイトル ) ]SendYes [ ( ウィンドウタイトル ) ]SendNo [ ( ウィンドウタイトル ) ]SendCommand( [ ウィンドウタイトル, ] コマンドID )PostMessage( [ ウィンドウタイトル, ] メッセージID, wParam, lParam )SendMessage( [ ウィンドウタイトル, ] メッセージID, wParam, lParam )int = SendMessage( [ ウィンドウタイトル, ] メッセージID, wParam, lParam )SendKeys( [ ウィンドウタイトル, ] 文字列 )SendKeys( "My window", "Hi, how are you?" )
SendKeys( "Some text" )SendSpecial( キー名 [ , 状態 ] )
SendSpecial( 91, "down" )
SendSpecial( 193, "down" )
SendSpecial( 193, "up" )
SendSpecial( 91, "up" )
SendSpecial [ ( ウィンドウタイトル [, Ctrl?, Shift? [, Alt? ]] ) ]SendCR( "ERROR" )
SendDown
SendHome( "", O, 1 ) (←行の先頭までをハイライトします。)Snapshot [ ( ウィンドウタイトル ) ]SendCtrlKey( [ ウィンドウタイトル, ] キー )SendCtrlKey( "v" ) は、Ctrl+V(クリップボードからペースト)を現在のウィンドウを送ります。MouseClick( [ ウィンドウタイトル, ] x, y )
RightMouseClick( [ ウィンドウタイトル, ] x, y )
MiddleMouseClick( [ ウィンドウタイトル, ] x, y )MouseDblClick( [ ウィンドウタイトル, ] x, y )
RightMouseDblClick( [ ウィンドウタイトル, ] x, y )
MiddleMouseDblClick( [ ウィンドウタイトル, ] x, y )MouseDown( [ ウィンドウタイトル, ] x, y )
MouseUp( [ ウィンドウタイトル, ] x, y )
RightMouseDown( [ ウィンドウタイトル, ] x, y )
RightMouseUp( [ ウィンドウタイトル, ] x, y )
MiddleMouseDown( [ ウィンドウタイトル, ] x, y )
MiddleMouseUp( [ ウィンドウタイトル, ] x, y )Sleep( ミリ秒 )SleepMessage( 秒, メッセージ [ , タイトル [ , OK許可? [ , 条件 ] ] ] )SleepMessage( 10, "Waiting for PocketWord", "Wait...", 0, ¥
wndExists( "Word" ))int = TimeStamp()
int = MakeTimeStamp( 年,月, 日
[, 時[, 分[, 秒 ]]] )string = FormatTime( フォーマット [, タイムスタンプ ] )x = FormatTime( "h:i:s a" )
x = FormatTime( "m/d/Y", TimeStamp() + 86400 )GetTime( 変数, 変数, 変数 )GetTime( 変数, 変数, 変数, 変数, 変数, 変数 )SetTime( 時, 分, 秒, [日, 月, 年] )
SetDate( 日, 月, 年 )Copy( 元ファイル, 先ファイル [, 上書き?])Copy( "¥My Documents¥test.txt", "¥Storage Card¥text.txt" )XCopy( 元ファイル, 先ディレクトリ [, 上書き? [, サブディレクトリ?] ] )XCopy( "¥My Documents¥*.txt", "¥Storage Card" )XCopy( "¥My Documents¥*.txt", "¥Storage Card", TRUE, TRUE )Rename( 元ファイル, 先ファイル [, 上書き?] )Move( 元ファイル, 先ディレクトリ [, 上書き? [, サブディレクトリ?] ] )Delete( ファイル )DelTree( ファイル )CreateShortcut( ショートカットファイル, ショートカット先ファイル [, 上書き? ])CreateShortcut( "¥Windows¥スタート メニュー¥Test.link", "¥Storage Card¥text.exe" )CreateShortcut( "¥Windows¥スタート メニュー¥Test.link", ¥
"""¥Program Files¥MortScript¥MortScript.exe"" ""¥Program Files¥MortScript¥Test.mscr""" )string = ReadFile( ファイル [, バイト数 [, 文字コード ] ] )
string = ReadLine( ファイル [, 文字コード ] )StatusType( ST_LIST, TRUE, FALSE )
StatusHistorySize( 500 )
line =ReadLine( "test.txt" )
While(NOT IsEmpty( line ))
StatusMessage( line )
line =ReadLine( "test.txt" )
EndWhileWriteFile( ファイル, 内容[, 追記?[, 文字コード ] ] )string = IniRead( INIファイル, セクション, エントリ )x = IniRead( "¥My Documents¥test.ini", "Settings", "Test" )IniWrite( INIファイル, セクション, エントリ, 値 )IniWrite( "¥My Documents¥test.ini", "Settings", "Test", "x" )SetComInfo( ポート, タイムアウト [, ボーレート [, パリティ [, ビット [, ストップビット [, コントロール ]]]]])data = ReadFile( "COM1:", 100 )bool = FileExists( ファイル )
bool = DirExists( ディレクトリ )int = FreeDiskSpace( ディレクトリ[, 単位 ] )int = TotalDiskSpace( ディレクトリ[, 単位 ] )int = FileSize( ファイル[, 単位 ] )int = FileCreateTime( ファイル )int = FileModifyTime( ファイル )bool = FileAttribute( ファイル, 属性 )SetFileAttribute( ファイル, 属性, セット? )SetFileAttribute( "¥Test.txt", "hidden", TRUE )SetFileAttribute( "¥Test.txt", "readonly", FALSE )SetFileAttribs( ファイル, 読み取り専用? [, 隠しファイル? [, アーカイブ? ]] )SetFileAttribs( "¥Test.txt", "", TRUE )SetFileAttribute( "¥Test.txt", FALSE )string = FileVersion( ファイル )
GetVersion( ファイル, 変数, 変数, 変数, 変数 )array = DirContents( ファイル, タイプ )
ZipFile( 元ファイル, ZIPファイル, アーカイブ内のファイル名 [, 圧縮レート ] )ZipFile( "¥Storage Card¥Test¥manual.psw", "¥Storage Card¥Test¥mans.zip", ¥
"test¥testman.psw" )ZipFiles( 元ファイル(複数), ZIPファイル [, サブディレクトリ? [, アーカイブ内のパス [, 圧縮レート ] ] ] )ZipFiles( "¥Storage Card¥Test¥*.psw", "¥Storage Card¥mans.zip", TRUE, "test" )ZipFiles( "¥Storage Card¥Test¥*.jpg, "¥Storage Card¥jpgs.zip" )UnzipFile( ZIPファイル, アーカイブ内のファイル名, 解凍先ファイル )UnzipFile( "¥Storage Card¥mans.zip", "test¥test.psw", ¥
"¥Storage Card¥test.psw" )
→「¥Storage Card¥mans.zip」の中の「test¥test.psw」を「¥Storage Card¥test.psw」として解凍します。UnzipAll( ZIPファイル, 解凍先ディレクトリ )UnzipPath( ZIPファイル, アーカイブ内のパス, 解凍先ディレクトリ )UnzipPath( "¥Storage Card¥mans.zip", "test", ¥
"¥Storage Card¥test-unzip" )
→「¥Storage Card¥mans.zip」の中のディレクトリ「test」以下のサブディレクトリを含む全てのファイルを、ディレクトリ「¥Storage Card¥test-unzip」以下に解凍します。たとえば、「test¥sub¥x.psw」は「¥Storage Card¥test-unzip¥sub¥x.psw」として解凍されます。Connect
Connect( 接続名 )
Connect( タイトル, メッセージ )CloseConnection
Disconnectbool = Connected()
bool = InternetConnected( [ URL ] )SetProxy( プロクシサーバー )Download( URL, 先ファイル )Download( "http://www.sto-helit.de/test.txt", ¥
"¥Storage Card¥test.txt" )MkDir( ディレクトリ )RmDir( ディレクトリ )ChDir( ディレクトリ )string = SystemPath( タイプ )Run( SystemPath( "ScriptExe" ) ¥ "MortScript.exe", ¥
SystemPath( "ScriptPath" ) ¥ SystemPath( "ScriptName" ) & ¥
SystemPath( "ScriptExt" ))value = RegRead( ルートキー, サブキー, 値名 )RegWriteString( ルートキー, サブキー, 値名, 値 )
RegWriteDWord( ルートキー, サブキー, 値名, 値 )
RegWriteBinary( ルートキー, サブキー, 値名, 値 )
RegWriteMultiString( ルートキー, サブキー, 値名, 配列 )RegWriteDWord( "HKCU", "Software¥Microsoft¥Inbox¥Settings", "SMSDeliveryNotify", 1 )RegWriteString( "HKCU", "Software¥Mort¥MortPlayer¥Skins", "Skin", "Night" )
RegWriteBinary( "HKCU", "Software¥Mort¥Dummy", "", "C000" )
RegWriteMultiString( "HKCU", "Software¥Mort¥Dummy", "Days", Array( "Mon", "Tue", "Wed" ) )bool = RegValueExists( ルートキー, サブキー, 値名 )bool = RegKeyExists( ルートキー, サブキー )RegDelete( ルートキー, サブキー, 値名)RegDeleteKey( ルートキー, サブキー, 値?, サブキー? )string = Input( メッセージ [, タイトル [, 数値? [, 複数行? [, デフォルト ]]]] )Message( テキスト [, タイトル ] )BigMessage( テキスト [, タイトル ] )SleepMessage( 秒, メッセージ [ , タイトル [ , OK許可? [ , 条件 ] ] ] )int = Question( 質問 [, タイトル [, タイプ ] ] )int = Choice( タイトル, プロンプト, デフォルト, タイムアウト, 値, 値 {, 値 } )
int = Choice( タイトル, プロンプト, デフォルト, タイムアウト, 配列 )string = SelectDirectory( タイトル, メッセージ [, デフォルト] )string = SelectFile( タイトル, 保存?, [フィルター [, メッセージ [, デフォルト]]] )SetChoiceEntryFormat( 選択肢サイズ [, フォントサイズ, フォント名 ] )SetMessageFont( フォントサイズ, フォント名 )StatusType( スタイル [, 表示継続? [, キャンセルボタン? ] ] )StatusInfo( タイトル [, 但し書き ] )StatusListEntryFormat( 選択肢サイズ [, フォントサイズ, フォント名 ] )StatusHistorySize( 表示数 )StatusMessage( メッセージ [, スタイル [, 表示継続? [, キャンセルボタン? ]]] )
StatusMessageAppend( テキスト )StatusMessage( "Step 1", ST_LIST, TRUE )
For i =1 to 10
StatusMessageAppend( "." )
Next
StatusMessageAppend( "OK" )
StatusMessage( "Finished" )
StatusRemoveLastMessage()
StatusClear()StatusShow()WriteStatusHistory( ファイル [, 追記? [, 文字コード ] ] )bool = SupportsProcHandling()bool = ProcExists( プロセス名 )bool = ScriptProcExists( スクリプト名 )string = ActiveProcess( [ フルパス? ] )string = WindowProcess( ウィンドウ名 [, フルパス? ] )Kill( プロセス名 )KillScript( スクリプト名 )backScript = SystemPath( "ScriptPath" ) ¥ "background.mscr"
If( ScriptProcExists( backScript ))
If(Question( "Stop background process?" ) = YES )
KillScript( "background.mscr" )
EndIf
Else
Run( backScript )
EndIfSetVolume( 値 )
int =Volume()PlaySound( WAVファイル )Vibrate( ミリ秒 )int = ColorAt( x, y )Array =ScreenToChars( x, y, 幅, 高さ, 色コード[, 背景色? [, 前景用文字[, 背景用文字 ]]] )int = RGB( red, green, blue )
int = Red( 色コード )
int = Green( 色コード )
int = Blue( 色コード )
Rotate( 方向 )SetBacklight( バッテリー, ACアダプタ )ToggleDisplay( オン? )
int = ScreenWidth()
int = ScreenHeight()
bool = Screen( タイプ )RedrawTodayShowWaitCursor
HideWaitCursorstring = CurrentCursor( [ウィンドウ名] )ShowInput
HideInputSetInput( 入力タイプ )SetClipText( テキスト )string = ClipText()int = FreeMemory( 単位 )int = TotalMemory( 単位 )bool = ExternalPowered()
int = BatteryPercentage()
int = BackupBatteryPercentage()
PowerOffIdleTimerResetvalue = SystemVersion( [ 要素 ] )string = MortScriptType()
string = MortScriptVersion()
GetMortScriptVersion( 変数, 変数, 変数, 変数 )
Reset