Skip to content

Instantly share code, notes, and snippets.

@azechi
Created January 19, 2018 08:37
Show Gist options
  • Save azechi/a8b70d05a0f01dec289a18421f6db92d to your computer and use it in GitHub Desktop.
Save azechi/a8b70d05a0f01dec289a18421f6db92d to your computer and use it in GitHub Desktop.
WindowsのSendToでWebページのショトートカットファイルを"[title url]"の文字にしてクリップボードに保存する
@fsi --exec %HOME%\bin\Clip_URLShortcut.fsx %* | clip
@pause
#r "Microsoft.VisualBasic.dll"
open System
open System.IO
open System.Runtime.InteropServices
open System.Text
open Microsoft.VisualBasic.FileIO
[<DllImport("kernel32.dll", CharSet = CharSet.Unicode)>]
extern int GetPrivateProfileString(string _section, string _key, string _def, StringBuilder _retVal, int _size, string _filePath);
let getUrl =
let buff = StringBuilder 255
fun path ->
buff.Clear() |> ignore
GetPrivateProfileString ("InternetShortcut", "URL", "", buff, 255, path) |> ignore
buff.ToString()
>> (fun s -> if String.IsNullOrWhiteSpace s then None else Some s)
Array.skip 1 fsi.CommandLineArgs
|> Array.filter (Path.GetExtension >> (=) ".url")
|> Array.map (fun path -> path, getUrl path)
|> Array.filter (snd >> Option.isSome)
|> Array.iter
(fun (path, url) ->
let title = Path.GetFileNameWithoutExtension path
printfn "[%s %s]" title url.Value
FileSystem.DeleteFile (path, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin)
)
@azechi
Copy link
Author

azechi commented Jan 19, 2018

ファイルは複数でも可
拡張子が".url"でiniファイル形式
"InternetShortcut"セクションの"URL"キーの値を取得する

URLが取得できたファイルはごみ箱に入れる

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