** [[OOobbs2/107]] [#l1cd5328]
-''サマリ'': Shell でファイルを環境に応じたプログラムで開く
-''環境'': Basic
-''状態'': 解決
-''投稿者'': [[はにゃ?]]
-''投稿日'': 2008-05-27 (Tue) 23:44:08
*** 質問 [#f2229e4f]
ある拡張機能の機能で要望をいただいたのですが、無理そうと思っていたところ環境変数を取得すればなんとかなりそうというわけで、試して見たところディストリビューション依存性が強いらしいことが分かりました。
いろんな種類のファイルを Shell ランタイム関数を利用して、環境に応じたアプリケーションで開こうと目論んでいます。
とりあえず、手持ちの環境で次のようにしてみました。
#code(ob){{
Sub ShellOpenFile( sOpenFile As String, Optional sOpenClient As String )
If IsMissing( sOpenClient ) OR sOpenClient = "" Then
sOpenClient = GetOpenClient()
End If
Shell(sOpenClient,0,sOpenFile)
End Sub
Function GetOpenClient()
Select Case GetPathSeparator()
Case chr(&H5C) ' win env
GetOpenClient = "rundll32.exe url.dll,FileProtocolHandler "
Exit Function
Case "/" '
Dim sDesktopType As String
sDesktopType = Environ("KDE_FULL_SESSION")
If LCase(sDesktopType) = "true" Then
' kde
GetOpenClient = "kfmclient exec"
Exit Function
End If
sDesktopType = Environ("GNOME_DESKTOP_SESSION_ID")
If sDesktopType <> "" Then
' gnome
GetOpenClient = "gnome-open"
Exit Function
End If
sDesktopType = Environ("DESKTOP_SESSION")
If LCase(Left(sDesktopType,4)) = "xfce" Then
' xfce
GetOpenClient = "exo-open"
Exit Function
End If
If sDesktopType = "" Then
sDesktopType = Environ("GDMSESSION")
If sDesktopType <> "" Then
GetOpenClient = GetOpenClient()
Exit Function
End If
End If
If LCase(sDesktopType) = "default" Then
sDesktopType = "xdg-open"
End If
If sDesktopType = "" Then
'
GetOpenClient = "open"
Exit Function
Else
' xdg-open
GetOpenClient = "xdg-open"
Exit Function
End If
End Select
End Function
}}
|環境|コマンド|
|Win|rundll32.exe url.dll,FileProtocolHandler |
|gnome|gnome-open|
|kde|kfmclient exec|
|kde4|kioclient exec|
|xfce|exo-open|
|--|xdg-open|
|Mac OS X|open|
*** 回答 [#v06aaec5]
- とりあえず、リンク http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/511443 -- はにゃ? &new{2008-05-28 (水) 00:40:18};
- 最終的に上記のように変更。自動で選択するには限界がありすぎるので、ウィザードで環境を選択させることに。選択されていない場合のみ調べるように。ディストリビューションによって違いすぎるので、完。-- はにゃ? &new{2008-05-28 (水) 210:40:18};
#comment
*** 感想,コメント,メモ [#a133ea29]
#comment