|
わたしの場合は、必ずと言ってよいくらい頻繁に使うファンクションです。特にスタンドアロンにしたスタックのアプリケーションと同じフォルダー内に、クイックタイムやイメージファイルを置いて引き出したりする時は、絶対に必要です。the filename でファイルまでのパスがわかるので、最後の
ファイル名だけ取り除けば、そのフォルダーまでのパスが得られるのですが、ちょっと MacOSX だけそのパスが違っているので、例外を作っておかなくてはいけません。(RunRev のスタックを作って行くときは、基本的にどの OS でも使えるようにしておいた方が、面倒がありません)

下に、スタックファイルが保存されているフォルダーパスを求めるファンクション theFolderPath() と、Mac OSX かどうかを判断するファンクション IsOSX() を書きます。
Mac OSX 上のスタンドアロンでは、アプリケーションのファイル構成が、他のOS でのスタンドアロンやMac OSX での 開発環境とは違いがあって、Mac OSX では the filename of this satck でファイルパスを取得すると、ファイル名とファイルのあるフォルダー間のファイルパスに、".app/Contents/MacOS/" というストリングが混じります。ですから、MacOSX でしかも、上記のストリングがあるかの判断をして(スタンドアロンか開発環境か)、それを取り除かなければいけません。その例外分だけ少し複雑になります。the platform で MacOS または Win32 などの OS の違いが取得できますから、さらに細かな判別を行います。
function theFolderPath
put the filename of this stack into tPath
set the itemdel to "/"
If (IsOSX()) then
get offset(".app/Contents/MacOS/", tPath)
if it > 0 then
delete char it to len(tPath) of tPath
end if
end if
delete last item of tPath
return tPath
end theFolderPath
function IsOSX
if the platform is not "MacOS" then return false
get the systemversion
set the itemdel to "."
if item 1 of it >= 10 then return true
return false
end IsOSX
RunRev では defaultFolderと言うのがあって、「デフォルト」ではアプリケーションをスタートアップした時に、 そのアプリケーションが入っているフォルダーとなります。たぶん defaultFolder がわかっているのに、何故 theFolderPath() が必要か疑問を持たれるかもしれませんね。理由は開発環境と、スタンドアロンとの defaultFolder に違いがあるためです。開発環境のデフォルトフォルダーは、Runtime Revolution 本体が入っているフォルダーになり、スタンドアロンではそのアプリケーションをスタートアップしたフォルダーになるので、ランタイムでテストする時と、そのスタックがスタンドアロンになった時とは、the defaultFolder に違いが出てしまいます。ですから、スタックのスタンドアロンを想定したデフォルトフォルダーに、開発中は直しておかなくてはいけません。
つまり
set the defaultFolder to theFolderPath()
が必要になります。
では the defaultFoler をセットしておくと何が便利かと言うと、デフォルトフォルダー内のファイルリスト、フォルダーリストを得る事ができる等の利便があるからです。次のスクリプトは、デフォルトフォルダー内のファイルリスト、フォルダーリストを得て、フィールド 1 に入れるスクリプトです。
set the defaultFolder to theFolderPath()
put the files &cr&cr& the folders in fld 1
ここではシンプルにファイルリストとフォルダーリストとのあいだは 1 行のアキだけとしていますが、 004.rev ではそれぞれのトップの行に、「-- // Files //---」「--// Folders //---」と入れています。
最後に実際のこのフォルダーを開けるスクリプトを書いておきます。Windows とMac OSX ではファイルパスの扱いに違いがあって、MacOSX のshell ではtheFolderPath() の前後をクオートでくくっています。
注意:Window版にNorton AutoProtectがインストールしてある場合、クラッシュする可能性があります。プログラム開始前にNorton AutoProtectの機能をを切る措置をしてください。
on mouseUp
set cursor to watch
if platForm() is "MacOS" then
OpenFolder quote& theFolderPath() "e
else
OpenFolder theFolderPath()
end if
end mouseUp
on openFolder pPath
switch (the platform)
case "Win32"
set the hideConsoleWindows to true
if the shellCommand is "cmd.exe" then
create alias "C:/Temp.lnk" to file pPath
get shell("C:\Temp.lnk")
delete file "C:/Temp.lnk"
else
get shell("start" && quote & pPath & quote)
end if
break
case "MacOS"
if the systemVersion >= 10 then
get shell("open " & pPath)
else
put "tell application " & quote & "Finder" & quote & cr & \
"activate" & cr & "open folder " & quote & \
ConvertPath(pPath) & quote & cr & "end tell" into tScript
do tScript as AppleScript
end if
break
end switch
end openFolder
function convertPath pPath
if char 1 to 9 of pPath = "/Volumes/" then
delete char 1 to 9 of pPath
else
put line 1 of the drives before pPath
end if
replace "/" with ":" in pPath
return pPath
end convertPath
参考:http://www.sonsothunder.com/devres/revolution/revolution.htm?_file009
他のスクリプトが、
Rev サンプルにありましたので、追加しておきます。(06年10月)
function basePath
if the environment is "development" then
set the itemdel to "/"
return item 1 to -2 of the filename of this stack
else
set the itemDelimiter to ":"
put item 2 to -1 of the address into tPath
set the itemDelimiter to "/"
switch the platform
case "MacOS"
put item 1 to -5 of tPath into tResult
break
case "Win32"
put item 1 to -2 of tPath into tResult
break
end switch
return tResult
end if
end basePath
|