メインコンテンツまでスキップ

ファイルとファイルシステムのローカルとグローバルプロパティ

ここで説明するローカルプロパティとグローバルプロパティは、SenseTalkスクリプトがファイルやファイルシステムオブジェクトにアクセスしたり、それらと対話したりする方法に影響します。SenseTalkでファイルやファイルシステムを操作するための追加情報については、File and Folder ReferencesFile and Folder Interactionを参照してください。

ローカルプロパティとグローバルプロパティの値を設定または変更する:

SenseTalkのコマンド Set または Put を使用してグローバルプロパティの値を設定できます。これらのプロパティを参照するときは、通常の変数と区別するためにプロパティ名の前に the を使用しなければなりません。

例:

set the searchrectangle to [1,2,2,3]
put 2 into the remoteworkinterval

このようにしてグローバルプロパティ内の特定の名前付きプロパティを追加または変更できます:

set the namedColors.pink to color("RGB,1.0,0.5,0.5") -- Adds pink to the namedColors global property and defines its RGB color value
set the listFormat's separator to " & " -- Sets the separator property of the listFormat global property

プロパティは、setoption または setoptions コマンドを使用して設定または更新することもできます。setoption コマンドでは一つのプロパティを更新でき、setoptions コマンドでは複数のプロパティを更新できます。

例:

setoption searchrectangle, [1,2,2,3]
setoptions {searchrectangle: [1,2,2,3], scriptlogging: yes}
ノート

setoption および setoptions は、グローバルプロパティおよびローカルプロパティの使用に特化しているため、これらのコマンドのコマンド構文でプロパティ名から the を省略します。

ローカルプロパティとグローバルプロパティの操作についての追加情報については、SenseTalkのローカルプロパティとグローバルプロパティを参照してください。

the folder, the directory Global Properties

値: 現在の作業ディレクトリのパス

デフォルト: 典型的にはドキュメントフォルダへのパスですが、この値はプリファレンスGeneralセクションのDefault Suite Directory設定を更新することで変更可能です。

振る舞い: このプロパティを使用すると、現在の作業フォルダにアクセスしたり、その値を変更したりできます。the folderによって返される値は、the folderNamesEndWithSlashグローバルプロパティがfalseに設定されていない限り、スラッシュで終わります。この最後のスラッシュは、以下の例に示すように、ファイル名を追加することでフルパス名を簡単に作成できるようにします。

ノート

SenseTalkスクリプト内では、folderdirectoryは同じ意味で使用されます。スクリプト中でfolderという語が使用されている場所では、代わりにdirectoryという語を使用できます。

例:

set the directory to "C:\Users\Carrie\Desktop\"

例:

set the folder to "C:\Users\Carrie\Desktop\"

例:

set the directory to "C:\Users\Carrie\Desktop\data\"
put the files of the folder into fileObjects // Returns a list of the file objects for any files in the current working directory and stores them in a variable

例:

set the folderNamesEndWithSlash to false
put the folder & "\newfile.txt" into filepath // Concatenates the / to create a valid path, because the / is not returned by the folder function
put "xyz" into file filepath

関連情報:

the folder, the directory グローバルプロパティ

値: True, False

デフォルト: True

振る舞い: このプロパティは、フォルダ名またはディレクトリ名が最後にスラッシュ付きで返されるかどうかを決定します。このプロパティは、the folderおよびthe directoryグローバルプロパティと、ディレクトリパスを返す各種のSenseTalkコマンドおよび関数に適用されます。 例:

例:

set the folderNamesEndWithSlash to false

例:

log the folder // Logs the current working directory with a slash at the end. For example: 'C:/Users/Carrie/Documents/'
set the folderNamesEndWithSlash to false
log the folder // Logs the current working directory without a slash at the end. For example: 'C:/Users/Carrie/Documents'

例:

set the folderNamesEndWithSlash to false
put the folder & "newfile.txt" into filePath
put "xyz" into file filePath

関連項目:

the strictFiles グローバルプロパティ

値: True, False

デフォルト: False

振る舞い: このプロパティは、ランタイム中のファイル使用に対するより厳密な制御を提供するために使用できます。このプロパティがTrueに設定されている場合、存在しないファイルをコンテナとして読み取ると、例外がスローされ、空を返すのではありません。

Falseに設定されている場合、存在しないファイルからの読み取りは、そのファイルが空であるかのように値を返します。この動作は、場合によっては予期しない結果をもたらすことがあります。例えば、ファイル名が間違って入力された場合、スクリプトはそれを空として扱い、ファイルが見つからないというエラーを出すのではなく。

例:

set the strictFiles to true

例:

set the StrictFiles to true
put file "C/Desktopmyfile.txt" into myData // Throws exception: StrictFilesViolation Attempt to read nonexistent file: C:/Users/Carrie/Documents/C/Desktopmyfile.txt'

関連情報:

  • the strictProperties
  • the strictVariables

the defaultStringEncoding グローバルプロパティ

値: 現在の文字列エンコーディング方法。利用可能な値の全リストを見るには、the availableStringEncodings()関数を使用します:

put availableStringEncodings()

デフォルト: UTF8

振る舞い: このプロパティは、テキスト文字列がファイル、ソケット、またはURLから読み込まれたり書き込まれたりするときにどのようにエンコードされるかを指定します。この設定は、readおよびwriteコマンドによって使用され、またファイルまたはURLをコンテナとして扱うときにも使用されます。the defaultStringEncodingの許容される値には、UTF8、Unicode、ASCIIなどがあります。

例:

set the defaultStringEncoding to "ASCII"

例:

put BlackDiamond as data // Displays '<e29786>'
set the defaultStringEncoding to "Unicode"
put BlackDiamond as data // Displays '<fffec625>'

例:

"C:\Users\Carrie\Desktop\Data\characters.txt" を filePath に入れます // このパスのファイルにはユニコード文字が含まれています
DefaultStringEncoding を "Unicode" に設定します
put file filePath // ファイルからユニコード文字を表示します。例えば: ʘʤϬϮ

例:

put the defaultStringEncoding into origEncoding
set the defaultStringEncoding to "Unicode" -- Full 16-bit Unicode text
put myInternationalText into file "/tmp/twoByteText"
set the defaultStringEncoding to origEncoding -- Restores original value

Tech Talk

SenseTalk内では、テキスト文字は単にそれ自体です:文字 A は文字 A であり、文字 é は文字 é(鋭いアクセント付きの e)です。しかし外部では、同じ文字がビットとバイトのシーケンスとして表されるさまざまな方法があります。それぞれのテキスト表現は エンコーディング と呼ばれます。SenseTalkが使用する標準エンコーディングはUTF8であり、これはUnicode文字をエンコードするための広く使用されている8ビットシステムです。

the umask グローバルプロパティ

値: 3桁の数字;詳細な説明については 動作 セクションを参照してください

デフォルト: 022

動作: 新しく作成されるファイルのposix権限マスクを設定または取得します。the umask プロパティを使用して、SenseTalkによって直接または間接的に作成された任意のファイルやフォルダのアクセス権限を制御します。マスクは3桁の数字であり、各桁はそれぞれユーザ、グループ、他のユーザのファイル権限を制御します。各桁は、ブロックされる権限を示す0から7までの数字です。値4は読み取り権限をブロックし、2は書き込み権限をブロックし、1は実行権限をブロックします。複数の権限をブロックするためには、これらの値を合計します。

例:

set the umask to 077

例:

put the umask into origMask
set the umask to 247 -- Set so user can't write, group members can't read, and others have all permissions blocked
create file "/tmp/permissionsTest"
set the umask to origMask -- Restore it to its original value

関連項目:

the autoSaveDatabaseUpdates グローバルプロパティ

値: True, False

set the folder to "/tmp/myWorkArea" -- Sets the working folder

動作: このプロパティは、データベースへの更新が自動的に保存されるかどうかを決定します。True に設定すると、すべての更新が自動的に保存されます。save changes コマンドを使用して手動で変更を書き込みたい場合は、このプロパティを False に設定します。

例:

set the autoSaveDatabaseUpdates to false

例:

set the autoSaveDatabaseUpdates to false // Turns off automatic updates
set info to table "memberinfo" of myDB
set member to the record of info where memberNumber is 16
Add 60 days to member's expirationDate
put "23" into member's memberNumber
put the records of info // Displays '((expirationdate:"2020-04-13", membernumber:"16"),(expirationdate:"2019-12-30", membernumber:"18"))'
save all changes to info // Sends all pending updates to the table
put the records of info // Displays '((expirationdate:"2019-12-30", membernumber:"18"),(expirationdate:"2020-06-12", membernumber:"23"))'

関連:

the shellCommand グローバルプロパティ

値: 実行したいシェルコマンドのフルパス; ShellExecute; 空

デフォルト: プラットフォームによります; 下記の 動作 セクションを参照してください。

動作: このプロパティは、shell コマンドまたは関数を使用したときにどのシェルプログラムを使用してコマンドを実行するかを制御します。デフォルトでは、Mac および Linux では the shellCommand/bin/sh (Bourne シェル)に設定されています。別のシェルでコマンドを実行するには、シェル関数を呼び出す前に the shellCommand を使用したいシェルのフルパスに設定するか、"ShellExecute" または空に設定します。

Windowsでは、the shellCommand グローバルプロパティのデフォルト設定は ShellExecute です。この設定は、指定されたファイルを実行するためにWindowsの ShellExecute() 関数が使用されることを意味します。

Windowsで ShellExecute を使用する場合、コマンドまたはファイル以外にも追加のパラメータをオプションで渡すことができます。2番目のパラメータ(指定された場合)は、実行されるコマンドに渡すパラメータを指定します。3番目のパラメータは、アクションのデフォルトの作業ディレクトリを指定します。4番目のパラメータは、基本的な ShellExecute() 関数に渡す任意のフラグを指定するための数値であるべきです。最後に、5番目のパラメータ(指定された場合)は、明示的な動詞を指定します(例えば open, explore, edit, find, print)。それ以外の場合は、レジストリ(または open)で定義されているデフォルトの動詞が使用されます。(ShellExecute を使用すると、出力は返されません。)エラーが発生した場合、the result は数値に設定されます。それ以外の場合は空になります。

the shellCommand が空でなく、ShellExecute に設定されていない場合(MacおよびLinuxでは通常のケースで、デフォルトでは /bin/sh に設定されています)、複数のパラメータがシェル関数に渡される場合、それらはそれぞれが一つのシェルのコンテキスト内で順番に実行される別のコマンドとして扱われます。

the shellCommand が空の場合、shell はその最初のパラメータを実行するコマンドとして扱い、その他の追加のパラメータをそのコマンドに渡すパラメータとして扱います。単一のパラメータのみが渡された場合、パラメータ内に存在する任意のスペースでそれが分割され、コマンドとそのパラメータが導き出されます。

テックトーク

set the shellCommand to "ShellExecute"
shell "example.bat" -- 指定されたバッチファイルを実行します

例:

set the shellCommand to empty
put shell("ls -l") -- '-l' パラメータ付きで 'ls' コマンドを実行します
put shell("ls", "-l") -- 同じことを行います
ノート

Windowsオペレーティングシステムにはシェルコマンドを実行するときの制限があります。Windowsでシェルコマンドを実行すると、シェルコマンドからの出力は表示されません。この問題を解決するために、コマンドの出力をファイルにリダイレクトします。スクリプトが完了した後、ファイルの内容を手動で読み取って結果を確認します。

shell "c:\windows\system32\cmd.exe", <</c "C:\Program Files (x86)\adt-bundle-windows-x86_64\sdk\platform-tools\adb" >> && MyCommand && "> someFile.txt"
put file "C:\wherever\someFile.txt"

関連: