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