Open file stored on OneDrive with local application Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
submeg
Posts: 326
Joined: 14 Apr 2017, 20:39
Contact:

Open file stored on OneDrive with local application

11 Dec 2019, 04:16

Hello all,

I am trying to open a file that is saved on my OneDrive, but with my local application, however I can't work out the syntax.

Opening a local file:

Code: Select all

Run, C:\Users\LOCALUser\Documents\FILENAME.docx
However, I tried to do the same thing for a file stored in my OneDrive:

Code: Select all


Run, Onenote.exe https://onedrive.live.com/view.aspx?resid=IDSTRING%212310&id=documents onenote:https://d.docs.live.net/IDSTRING2/Documents/OneNote%20Book%20Name/

Firstly, it doesn't like the spaces that are replaced with %20, as it sees the percentage sign as an illegal character. However, even with another link that doesn't contain them, it opens the file in a browser.

Is it possible to open a file stored on OneDrive with a local application? Thanks for any help.

Submeg
User avatar
submeg
Posts: 326
Joined: 14 Apr 2017, 20:39
Contact:

Re: Open file stored on OneDrive with local application  Topic is solved

22 Jun 2021, 05:12

I found the solution to this lies in the Office URI scheme.

I ended up creating a script for creating the hyperlinks to open the file stored in OneDrive with the native application as per below.

Note:For files stored in a Teams site, you need to grab the filepath from the sharepoint location; the links that teams creates are a mess and have no obvious structure.

Code: Select all


;-------------------------------------------------------------	
OpenSite_CreateProgramHyperlink()
{
InputBox FileToOpen, Which file do you wish to open?, Please enter the file's URL:

Haystack := FileToOpen
HaystackLength := StrLen(Haystack)

StartPoint := 0
BreakPoint := 0
Needle := "?"

IfInString, Haystack, %Needle%
{

	;remove the end of the path after ?
	
	BreakPoint := InStr(Haystack, Needle)
	
	;msgbox % BreakPoint
	
	Haystack := SubStr(Haystack,1, BreakPoint - 1)
	
	;msgbox % Haystack
	
	;extract between sharepoint.com/ and /sites
	
	Needle := "sharepoint.com"
	StartPoint := InStr(HayStack,Needle)
	
	;msgbox % StartPoint
	
	Needle := "/sites"
	BreakPoint := InStr(HayStack, Needle)
	
	;msgbox % BreakPoint
	
	
	;Cleaned hyperlink, now add the program to open with
	Haystack := Trim(SubStr(HayStack,1,StartPoint+13) . SubStr(Haystack,BreakPoint,StrLen(Haystack) + 1 - BreakPoint))
	
	InputBox ChosenProgram, Native program?, Which program should it be opened with (write in lowercase)
	
	Switch ChosenProgram
	{
	Case "word":
	
		ProgramIs := "ms-word:ofe|u|"
	
	Case "excel":
		
		ProgramIs := "ms-excel:ofe|u|"
	
	Case "visio":
	
		ProgramIs := "ms-visio:ofe|u|"
	
	Default:
	
		msgbox Program isn't in the list; consider adding it
	
	}
	
	Haystack := ProgramIs . Haystack
	
	msgbox % Haystack
	
	Clipboard = 
	
	Clipboard := Haystack

}
else
{
	msgbox % "Check your hyperlink and try again."
	
}

}
Return 

;-------------------------------------------------------------	

____________________________________
Check out my site, submeg.com
Connect with me on LinkedIn
Courses on AutoHotkey :ugeek:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Frogrammer, gongnl and 276 guests