Opening a file through powershell with the path containing spaces

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Swiftly9767
Posts: 11
Joined: 15 Aug 2023, 06:17

Opening a file through powershell with the path containing spaces

16 Apr 2024, 10:33

I want to open an image file with a specific image viewer using the powershell command line through Autohotkey:

Code: Select all

; Path to an image file
image_path := "D:\slideshow\images\Ancient Paintings\Games in honor of Patroclus during his funeral - Carle Vernet, 1790.jpg"
; Path to image viewer
viewer_path :=  "C:\Program Files\BandiView\BandiView.exe"
; Powershell command
Run, PowerShell "& viewer_path viewer -fullscreen -r -ss:30 image_path",, Hide
I can't seem to find the correct inclusion of the path variables.

If I run this command in powershell, it works:

Code: Select all

& "C:\Program Files\BandiView\BandiView.exe" viewer -fullscreen -r -ss:30 "D:\slideshow\images\Ancient Paintings\Games in honor of Patroclus during his funeral - Carle Vernet, 1790.jpg"
Swiftly9767
Posts: 11
Joined: 15 Aug 2023, 06:17

Re: Opening a file through powershell with the path containing spaces

16 Apr 2024, 10:45

I got it to work, you need to escape the quotes mutliple times:
; Path to an image file
imagePath := "F:\bilder\SELECTION\categories\Architecture\309.jpg"
; Path to image viewer
viewerPath := "C:\Program Files\BandiView\BandiView.exe"
; Construct the PowerShell command with proper escaping
Run, PowerShell "& """%viewerPath%""" viewer -fullscreen -r -ss:30 """%imagePath%""" ", , Hide

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: IfThenElse, lechat, LuckyJoe, osail and 259 guests