C#(.NET Core)で今読んでいるKindle本のタイトルを取得する
Windows用のKindle for PCから、今開いている本のタイトルを取得するコンソールアプリ。
環境
- Visual Studio Code: 1.50.1
- .NET Core 3.1
コード例
Kindle for PCのプロセスを取得後、メインウィンドウのタイトルを取得して本のタイトルを抽出しています。
クリップボードにコピーするところまでやりたかったのですが、VS Code+.NET CoreでClipboard
クラスを使う方法が分からなかったので、コンソールに表示するところまで実装しました。(Gistを使ってみたかったので、とりあえず記事にしてみました。)
完全版はPython等で作ってみようと思います。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace cs_20201030_1 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
// Kindleのプロセスを取得 | |
System.Diagnostics.Process[] p = System.Diagnostics.Process.GetProcessesByName("kindle"); | |
// 本のタイトルを取得 | |
string[] title = p[0].MainWindowTitle.Split(" - "); | |
Console.WriteLine(title[1]); | |
} | |
} | |
} |