Skip to content

Instantly share code, notes, and snippets.

@t2psyto
Forked from valda/emacsclientw.vbs
Last active August 29, 2015 14:22
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save t2psyto/5e2491606f521bc3e5cd to your computer and use it in GitHub Desktop.
Save t2psyto/5e2491606f521bc3e5cd to your computer and use it in GitHub Desktop.
emacsclient のラッパスクリプトemacs.exe プロセスの有無と引数の有無に応じて startup_emacs.exe、startup_emacsclient.exe を起動。
'
' C:\gnupack_devel\emacsclientw.vbs
'
Set objShell = WScript.CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_Process")
Dim emacsProcess
emacsProcess = null
For Each objItem in colItems
If InStr(objItem.CommandLine, "emacs.exe") Then
Set emacsProcess = objItem
End If
Next
If WScript.Arguments.Count >= 1 Then
ReDim args(WScript.Arguments.Count-1)
For i = 0 To WScript.Arguments.Count-1
args(i) = WScript.Arguments(i)
Next
strArgs = """" & Join(args, """ """) & """"
If IsNull(emacsProcess) Then
objShell.Run("""" & fso.GetParentFolderName(WScript.ScriptFullName) & "\startup_emacs.exe"" " & strArgs)
Else
objShell.Run("""" & fso.GetParentFolderName(WScript.ScriptFullName) & "\startup_emacsclient.exe"" " & strArgs)
End If
Else
If IsNull(emacsProcess) Then
objShell.Run("""" & fso.GetParentFolderName(WScript.ScriptFullName) & "\startup_emacs.exe""")
Else
objShell.AppActivate("emacs ")
End If
End If
@t2psyto
Copy link
Author

t2psyto commented Jun 2, 2015

gnupack用にstartup_emacs.exeを使うようにした。
ファイルが複数渡された場合、全部開くようにした。

@t2psyto
Copy link
Author

t2psyto commented Jun 2, 2015

プロセスID指定で「objShell.AppActivate emacsProcess.ProcessID」してもアクティブにならなかった。。
emacsウィンドウが最小化状態だとAppActivateしても前面に出てこない。。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment