#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions
###インストールするパッケージ
set listPackage to {"pip", "pypdf", "pypdf", "pdfautonup", "setuptools-scm", "stdeb", "PyPDF2", "PyPDF3", "pdfnup"} as list
try
do shell script "/usr/bin/xcode-select --install"
end try
##
try
set strCmdText to ("/bin/mkdir -p $HOME/bin") as text
do shell script strCmdText
set strCmdText to ("/bin/chmod 700 $HOME/Library/Caches/pip") as text
do shell script strCmdText
end try
##
try
set strCmdText to ("/bin/mkdir -p $HOME/Library/Caches/pip") as text
do shell script strCmdText
set strCmdText to ("/bin/chmod 777 $HOME/Library/Caches/pip") as text
do shell script strCmdText
end try
##
try
set strCmdText to ("/bin/mkdir -p $HOME/Library/Python/3.9/lib/python/site-packages") as text
do shell script strCmdText
set strCmdText to ("/bin/chmod 755 $HOME/Library/Python/3.9/lib/python/site-packages") as text
do shell script strCmdText
end try
## python3のパスチェック
try
set strCmdText to ("/usr/bin/which python3") as text
set strResponse to (do shell script strCmdText) as text
on error
return "python3が見つかりませんでした終了します"
end try
########################
#install
repeat with itemPackage in listPackage
set strPackageName to itemPackage as text
tell application "Terminal"
set strCmdText to ("\"" & strResponse & "\" -m pip install --user \"" & strPackageName & "\"") as text
do script strCmdText
activate
end tell
repeat 5 times
tell application "Terminal"
set numCntWindow to (count of every window) as integer
if numCntWindow = 1 then
log "Windowがありません"
exit repeat
end if
tell front window
set numWindowID to id
tell front tab
set boolBusy to busy as boolean
end tell
end tell
end tell
if boolBusy is false then
log "処理していないので閉じる"
tell application "Terminal"
do script "\n\n" in window id numWindowID
do script "exit" in window id numWindowID
delay 1
close front window saving no
end tell
exit repeat
else
log "busyなので1秒まつ"
delay 1
end if
end repeat
tell application "Terminal"
set numCntWindow to (count of every window) as integer
end tell
if numCntWindow = 1 then
log "Windowがありません"
else
###
tell application "Terminal"
tell front window
set numWindowID to id
tell front tab
set boolBusy to busy as boolean
end tell
end tell
end tell
if boolBusy is true then
tell application "System Events"
tell application "Terminal" to activate
keystroke "c" using {control down}
end tell
tell application "Terminal"
do script "\n\n" in window id numWindowID
do script "exit" in window id numWindowID
delay 1
close front window saving no
end tell
end if
end if
end repeat
########################
#upgrade
repeat with itemPackage in listPackage
set strPackageName to itemPackage as text
tell application "Terminal"
set strCmdText to ("\"" & strResponse & "\" -m pip install --upgrade --user \"" & strPackageName & "\"") as text
do script strCmdText
activate
end tell
repeat 5 times
tell application "Terminal"
set numCntWindow to (count of every window) as integer
if numCntWindow = 1 then
log "Windowがありません"
exit repeat
end if
tell front window
set numWindowID to id
tell front tab
set boolBusy to busy as boolean
end tell
end tell
end tell
if boolBusy is false then
log "処理していないので閉じる"
tell application "Terminal"
do script "\n\n" in window id numWindowID
do script "exit" in window id numWindowID
delay 1
close front window saving no
end tell
exit repeat
else
log "busyなので1秒まつ"
delay 1
end if
end repeat
tell application "Terminal"
set numCntWindow to (count of every window) as integer
end tell
if numCntWindow = 1 then
log "Windowがありません"
else
###
tell application "Terminal"
tell front window
set numWindowID to id
tell front tab
set boolBusy to busy as boolean
end tell
end tell
end tell
if boolBusy is true then
tell application "System Events"
tell application "Terminal" to activate
keystroke "c" using {control down}
end tell
tell application "Terminal"
do script "\n\n" in window id numWindowID
do script "exit" in window id numWindowID
delay 1
close front window saving no
end tell
end if
end if
end repeat
display notification "処理終了" with title "処理が終了" subtitle "処理が終了しました" sound name "Sonumi"
return