Skip to content

Instantly share code, notes, and snippets.

@glfruit
Created December 27, 2015 05:56
Show Gist options
  • Save glfruit/6e7218abb6a1449d4016 to your computer and use it in GitHub Desktop.
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
[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