Created
December 27, 2015 05:56
-
-
Save glfruit/6e7218abb6a1449d4016 to your computer and use it in GitHub Desktop.
A simple PowerShell script to activate Zotero search dialog while writing in Scrivener
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[CmdletBinding()] | |
Param( | |
) | |
Add-Type @" | |
using System; | |
using System.Runtime.InteropServices; | |
public class Zotero { | |
[DllImport("user32.dll")] | |
[return: MarshalAs(UnmanagedType.Bool)] | |
public static extern bool SetForegroundWindow(IntPtr hWnd); | |
} | |
"@ | |
add-type -AssemblyName microsoft.VisualBasic | |
add-type -AssemblyName System.Windows.Forms | |
try { | |
$ScrivenerHandle = (Get-Process Scrivener).MainWindowHandle | |
$ref = iex "curl 'http://localhost:23119/better-bibtex/cayw?format=pandoc'" | |
[Microsoft.VisualBasic.Interaction]::AppActivate((Get-Process Scrivener).ID) | |
[System.Windows.Forms.SendKeys]::SendWait($ref) | |
[Zotero]::SetForegroundWindow($ScrivenerHandle) | |
} catch { | |
Write-Error "Failed to get active Window details. More Info: $_" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment