Skip to content

Instantly share code, notes, and snippets.

@ryancollingwood
Created August 29, 2016 03:22
Show Gist options
  • Save ryancollingwood/b8368fa227f7080595a54f454ed7c293 to your computer and use it in GitHub Desktop.
Save ryancollingwood/b8368fa227f7080595a54f454ed7c293 to your computer and use it in GitHub Desktop.
If you use the google drive desktop application on Windows, and want to launch your Google Docs, Sheets, etc. from explorer - then this could help.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace GoogleDocsLauncher
{
class Program
{
static void Main(string[] args)
{
if (args.Length == 0)
{
Console.WriteLine("No file specified");
return;
}
else
{
Console.WriteLine(args[0]);
}
String sChrome = String.Format(@"{0}\Google\Chrome\Application\chrome.exe", ProgramFilesx86());
String sUrl = GetUrl(args[0]);
System.Diagnostics.Process.Start(sChrome, sUrl);
}
private static string ProgramFilesx86()
{
if (8 == IntPtr.Size
|| (!String.IsNullOrEmpty(Environment.GetEnvironmentVariable("PROCESSOR_ARCHITEW6432"))))
{
return Environment.GetEnvironmentVariable("ProgramFiles(x86)");
}
return Environment.GetEnvironmentVariable("ProgramFiles");
}
private static String GetUrl(String Filename)
{
string json = String.Empty;
if (! File.Exists(Filename))
{
Console.WriteLine("Specified File Doesn't Exist!: {0}", Filename);
return String.Empty;
}
using (StreamReader r = new StreamReader(Filename))
{
json = r.ReadToEnd();
}
if (! String.IsNullOrEmpty(json))
{
dynamic stuff = JObject.Parse(json);
return stuff.url;
}
return String.Empty;
}
}
}
@ryancollingwood
Copy link
Author

Requires Newtonsoft.Json, and assumes you're using the Chrome Webbrowser.

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