20260527

[AppleScript]Kindleページ送り RTL 右から左へ 見開き表示用

[AppleScript]Kindleページ送り

NOTE記事一覧ですnote.com
 

【スクリプトエディタで開く】 |

Kindleページ送り.applescript.scpt
ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003(*
004
005Kindleのページ送り
006日本語版用 見開き表示分ページ送り
007
008
009com.cocolog-nifty.quicktimer.icefloe *)
010----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
011use AppleScript version "2.8"
012use framework "Foundation"
013use framework "AppKit"
014use framework "CoreGraphics"
015use scripting additions
016property refMe : a reference to current application
017property ocidNotFound : a reference to 9.22337203685477E+18 + 5807
018
019#################################
020#総ページ数
021set numCntPage to (183) as integer
022## 1ページ(見開き)での滞留時間
023set numInterval to 4 as integer
024
025#################################
026#本処理
027########################
028# ダイアログ
029set strTitle to ("入力してください") as text
030set strMsg to ("メイン画面下に出る総ページ数") as text
031set strDefaultAnswer to (numCntPage) as text
032set strOK to ("OK") as text
033set strCancel to ("キャンセル") as text
034set listButtons to {strOK, strCancel} as list
035set strIconFilePath to ("/System/Library/CoreServices/Finder.app/Contents/Resources/Finder.icns") as text
036set aliasIconFilePath to (POSIX file strIconFilePath) as alias
037try
038   tell application "System Events"
039      activate
040      set recordResponse to (display dialog strMsg with title strTitle default answer strDefaultAnswer buttons listButtons default button strOK cancel button strCancel with icon aliasIconFilePath giving up after 60 without hidden answer) as record
041   end tell
042on error strErrorMes number numErrorNO
043   log strErrorMes & numErrorNO
044   return false
045end try
046set boolGaveUP to (gave up of recordResponse) as boolean
047set strButtonReturned to (button returned of recordResponse) as text
048try
049   tell application "System Events" to quit
050end try
051if recordResponse is false then
052   log "キャンセル終了"
053   return false
054else if true is boolGaveUP then
055   log "時間切れですやりなおしてください"
056   return false
057else if strCancel is strButtonReturned then
058   log "キャンセル終了"
059   return false
060end if
061
062set strResponse to (text returned of recordResponse) as text
063set ocidOrgStrings to (refMe's NSString's stringWithString:(strResponse))
064set ocidResponseString to (ocidOrgStrings's stringByReplacingOccurrencesOfString:(return) withString:(""))
065set ocidResponseString to (ocidResponseString's stringByReplacingOccurrencesOfString:(linefeed) withString:(""))
066set ocidResponseString to (ocidResponseString's stringByReplacingOccurrencesOfString:(tab) withString:(""))
067set ocidResponseString to (ocidResponseString's stringByReplacingOccurrencesOfString:(space) withString:(""))
068##半角にして
069set ocidNumberString to ocidResponseString's stringByApplyingTransform:(refMe's NSStringTransformFullwidthToHalfwidth) |reverse|:(false)
070###数字以外の文字が
071set ocidDigitsCharSet to (refMe's NSCharacterSet's decimalDigitCharacterSet)
072set ocidNotDigitsCharSet to ocidDigitsCharSet's invertedSet()
073set ocidMatch to ocidNumberString's rangeOfCharacterFromSet:(ocidNotDigitsCharSet)
074set ocidLocation to ocidMatch's location()
075#NotFoundの反対=数字以外の文字があったら
076if ocidLocationocidNotFound then
077   log "数字以外の文字がありました"
078   return false
079end if
080set ocidReplacedStrings to ocidNumberString as string
081set numCntPage to ocidReplacedStrings as integer
082#ページ送りは1ページ少なく
083set num2upPage to (round (numCntPage / 2) rounding down) as integer
084
085
086###メインモニタのサイズ PT
087set ocidScreensArray to refMe's NSScreen's screens()
088set appMainScreen to ocidScreensArray's firstObject()
089set rectMailScreen to appMainScreen's frame()
090set originMainScreen to (first item of rectMailScreen) as list
091set sizeMainScreen to (last item of rectMailScreen) as list
092set numWpt to (first item of sizeMainScreen) as integer
093set numHpt to (last item of sizeMainScreen) as integer
094
095###メインモニタのサイズ PX
096set numMainDisplayID to refMe's CGMainDisplayID()
097set numWpx to refMe's CGDisplayPixelsWide(numMainDisplayID)
098set numHpx to refMe's CGDisplayPixelsHigh(numMainDisplayID)
099
100##SYSTEM EVENTS用のマルチリンガル対応用
101tell application id "com.apple.finder"
102   set strView to (localized string ("206.title") from table ("MenuBar")) as text
103   set strFullScreen to (localized string ("300944.title") from table ("MenuBar")) as text
104   set strExitFullScreen to (localized string ("FV20") from table ("LocalizableMerged")) as text
105end tell
106
107
108###フルスクリーンにする
109tell application id "com.amazon.Lassen"
110   activate
111   tell application "System Events"
112      tell application process "Kindle"
113         try
114            click menu item strFullScreen of menu 1 of menu bar item strView of menu bar 1
115         end try
116      end tell
117   end tell
118end tell
119#ここはフルスクリーン移行の待ち時間
120delay 2
121
122repeat with itemNo from 1 to num2upPage by 1
123   
124   
125   delay numInterval
126   #次のページへ
127   tell application id "com.amazon.Lassen" to activate
128   tell application "System Events"
129      tell application process "Kindle"
130         key code 123
131      end tell
132   end tell
133   
134end repeat
135
136delay 2
137#フルスクリーンを終了させる
138tell application id "com.amazon.Lassen"
139   activate
140   tell application "System Events"
141      tell application process "Kindle"
142         try
143            click menu item strExitFullScreen of menu 1 of menu bar item strView of menu bar 1
144         end try
145      end tell
146   end tell
147end tell
148
149return
150
151
AppleScriptで生成しました