Terminal

ターミナル 実行中のプロセスの終了とウィンドウを閉じる


AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002use AppleScript version "2.4"
003use scripting additions
004
005set numMaxCnt to 10 as integer
006set numCntSec to 0 as integer
007
008
009tell application id "com.apple.Terminal" to quit
010delay 1
011tell application "Terminal" to launch
012tell application "Terminal"
013  do script "\n"
014  delay 1
015  do script "tail -f /var/log/system.log" in front tab of front window
016end tell
017
018
019repeat numMaxCnt times
020  tell application "Terminal"
021    set boolRunning to not (running)
022    tell front window
023      tell front tab
024        set boolbusy to busy as boolean
025      end tell
026    end tell
027  end tell
028  set numCntSec to numCntSec + 1 as integer
029  if numCntSec ≥ numMaxCnt then
030    exit repeat
031  else
032    delay 1
033  end if
034end repeat
035##コントロールCを送って中断させる
036if boolbusy is true then
037  tell application "Terminal"
038    activate
039    tell front window
040      activate
041      tell front tab
042        activate
043        tell application "System Events"
044          tell process "Terminal"
045            key down {control}
046            keystroke "c"
047            key up {control}
048          end tell
049        end tell
050      end tell
051    end tell
052  end tell
053end if
054
055tell application "Terminal"
056  activate
057  do script "exit" in front tab of front window
058end tell
059delay 1
060tell application "Terminal"
061  activate
062  tell front window
063    close
064  end tell
065end tell
066
067
068tell application "Terminal" to quit
AppleScriptで生成しました

|

[Terminal]スクリプト実行後終了したらTerminalも終了する


AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004# com.cocolog-nifty.quicktimer.icefloe
005----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
006use AppleScript version "2.8"
007use framework "Foundation"
008use scripting additions
009
010property refMe : a reference to current application
011
012
013#実行するコマンド
014set strCommandText to ("~/bin/topgrade/topgrade") as text
015#プロセス名の判定用
016set strProcesseName to ("topgrade") as text
017
018tell application id "com.apple.Terminal"
019  #起動 を先にすることで新規Windowを作らない
020  launch
021  #前面に
022  activate
023end tell
024
025#ターミナル
026tell application "Terminal"
027  set numCntWindow to (count of every window) as integer
028  if numCntWindow = 0 then
029    #ウィンドウが無いなら
030    #新規Windowでシェルを実行
031    set objWindowID to (do script "/bin/bash\n\n")
032    set boolBusy to false as boolean
033    delay 1
034  else
035    #ウィンドウがある場合
036    tell front window
037      tell front tab
038        #前面のタブが処理中か?確認して
039        set boolBusy to busy as boolean
040      end tell
041    end tell
042    #処理中なら新規windowを作る
043    if boolBusy is true then
044      set objWindowID to (do script "/bin/bash\n\n")
045    else
046    #処理中では無いならそのWindowを使う
047      tell front window
048        set objWindowID to front tab
049      end tell
050    end if
051  end if
052  
053  #WidnowのIDを取得
054  do script strCommandText in objWindowID
055  #確実にウィンドウが出来るのをまつ
056  delay 1
057  tell front window
058    tell front tab
059      #プロセスが終わるまで繰り返し
060      repeat
061        #フロントタブで実行中のプロセス
062        set listProcesses to processes as list
063        set ocidProcessArray to refMe's NSArray's arrayWithArray:(listProcesses)
064        #終了判定
065        set boolContain to (ocidProcessArray's containsObject:(strProcesseName)) as boolean
066        #終了判定が YESなら
067        if boolContain is false then
068          #リピートを抜けて終了処理に
069          exit repeat
070        else if boolContain is true then
071          #終了判定がNO
072          set strTitle to custom title as text
073          #ここはカスタマイズが必要
074          if strTitle contains "Awaiting user" then
075            #ユーザー応答が必要になった場合は終了
076            exit repeat
077          end if
078          delay 1
079        end if
080      end repeat
081      #コマンドが終了したら
082      do script "\n\n" in objWindowID
083      #シェルをEXITして BASHを抜ける
084      do script "exit" in objWindowID
085      #コマンドが終了したら
086      do script "\n\n" in objWindowID
087      #シェルをEXITして ZSHを抜ける
088      do script "exit" in objWindowID
089      delay 1
090    end tell
091  end tell
092  close front window saving no
093  set numCntWindow to (count of every window) as integer
094  if boolBusy is false then
095    repeat with itemWindowID from 1 to (numCntWindow) by 1
096      close window itemWindowID saving no
097    end repeat
098    try
099      quit
100    end try
101  end if
102end tell
103
AppleScriptで生成しました

|

bash用 コマンドが終了したらターミナルのウィンドウを閉じる


AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002
003
004#実行するコマンド
005#XProtectのマルウェアスキャン実行
006set strCommandText to ("/Library/Apple/System/Library/CoreServices/XProtect.app/Contents/MacOS/XProtect") as text
007
008#ターミナル
009tell application "Terminal"
010  #起動
011  launch
012  #前面に
013  activate
014  #新規Windowでシェルを実行
015  set objWindowID to (do script "/bin/bash\n\n")
016  delay 1
017  #WidnowのIDを取得
018  do script strCommandText in objWindowID
019  #確実にウィンドウが出来るのをまつ
020  delay 1
021  tell front window
022    tell front tab
023      #プロセスが終わるまで繰り返し
024      repeat
025        #フロントタブで実行中のプロセス
026        set listProcesses to processes as list
027        #処理終了のデフォルト値 NO
028        set boolProcessesDone to false as boolean
029        #プロセスリストの数だけ繰り返し
030        repeat with itemProcesses in listProcesses
031          #プロセス名がコマンドラインの内容に含んでいるか?
032          set boolContain to (strCommandText contains itemProcesses) as boolean
033          #含んでいる=まだ実行中
034          if boolContain is true then
035            #終了判定 NO
036            set boolProcessesDone to false as boolean
037          else
038            #プロセス名が含まれない場合は 終了判定YES
039            set boolProcessesDone to true as boolean
040          end if
041        end repeat
042        #プロセス名を巡回チェックして
043        #終了判定が YESなら
044        if boolProcessesDone is true then
045          #リピートを抜けて終了処理に
046          exit repeat
047        else if boolProcessesDone is false then
048          #終了判定がNOなら 1秒まつ
049          delay 1
050        end if
051      end repeat
052      #コマンドが終了したら
053      do script "\n\n" in objWindowID
054      #シェルをEXITして BASHを抜ける
055      do script "exit" in objWindowID
056      #コマンドが終了したら
057      do script "\n\n" in objWindowID
058      #シェルをEXITして ZSHを抜ける
059      do script "exit" in objWindowID
060      delay 1
061    end tell
062  end tell
063  close front window saving no
064    set numCntWindow to (count of every window) as integer
065  
066  repeat with itemWindowID from 1 to (numCntWindow) by 1
067    close window itemWindowID saving no
068  end repeat
069end tell
070
071
072
AppleScriptで生成しました

|

[Terminal] python3 pip のアップデートとパッケージのアップデート


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

#!/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


|

[Terminal]コマンド実行後指定秒数で終了し閉じる


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

#!/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 numMaxRepeatTime to 5 as integer

###実行するコマンド
tell application "Terminal"
activate
do script "/sbin/ping www.yahoo.co.jp"
end tell
delay 2


###くりかえし
repeat numMaxRepeatTime times
  tell application "Terminal"
    ##Windowの数を数えて
    set numCntWindow to (count of every window) as integer
    if numCntWindow = 1 then
log "Windowがありません"
      exit repeat
    end if
    tell front window
      ##WindowIDを取得
      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"
  tell front window
    set numWindowID to id
    tell front tab
      ##今一度実行中か?確認して
      set boolBusy to busy as boolean
    end tell
  end tell
end tell
###実行中ならCTL+Cを送って中断させて
if boolBusy is true then
  tell application "System Events"
    tell application "Terminal" to activate
keystroke "c" using {control down}
  end tell
  ##Windowを閉じる
  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



return


|

[Terminal]ウィンドウ設定が常にタブの場合も新規ウィンドウを開く


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

#!/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 framework "AppKIt"
use framework "UniformTypeIdentifiers"
use scripting additions

set strBundleID to "com.apple.Terminal"

###起動はランチを使うと新規ウィンドウが出来ない
tell application "Terminal" to launch
###ウィンドウの数を数えて
tell application "Terminal"
  activate
  set numCntWindow to (count of every window) as integer
end tell
###ウィンドウが無いなら終了する
if numCntWindow = 0 then
  tell application "Terminal" to quit
  delay 2
  tell application "Terminal" to launch
end if
####新規ウィンドウを開く(SystemEvent方式)
tell application "Terminal"
  activate
  tell application "System Events"
    tell process "Terminal"
      set frontmost to true
key down {command}
      keystroke "n"
key up {command}
    end tell
  end tell
end tell
###システムイベントの場合ウィンドウが出来るのを待つ
repeat 5 times
  tell application "Terminal"
    set numCntWindow to (count of every window) as integer
  end tell
  if numCntWindow = 0 then
    delay 0.5
  else
    exit repeat
  end if
end repeat

tell application "Terminal"
  tell front window
    set numWindowID to id as integer
  end tell
  tell window id numWindowID
    set position to {0, 25}
  end tell
end tell
###新規ウィンドウを開く(do script方式)
tell application "Terminal"
  launch
  activate
  set objTabWindows to do script "\n"
  tell objTabWindows
    activate
  end tell
end tell
####新規ウィンドウを開く
tell application "Terminal"
  activate
  tell application "System Events"
    tell process "Terminal"
      set frontmost to true
click menu item "タブを新しいウインドウに移動" of menu 1 of menu bar item "ウインドウ" of menu bar 1
    end tell
  end tell
  tell front window
    set numWindowID to id as integer
  end tell
  tell window id numWindowID
    set position to {0, 340}
  end tell
end tell

|

[Terminal]起動方法によるウィンドウ生成の違い


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

tell application "Terminal" to launch
-->新規ウィンドウが出来ない
tell application "Terminal" to activate
-->新規ウィンドウが出来る

|

[zsh_sessions]セッションファイルを起動時に削除


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

#!/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 framework "AppKit"
use scripting additions

property refMe : a reference to current application


###ディレクトリ
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidTempDirURL to appFileManager's temporaryDirectory()
###ひとつ階層上
set ocidContainerDirPathURL to ocidTempDirURL's URLByDeletingLastPathComponent()
set ocidCleanupDirPathURL to ocidContainerDirPathURL's URLByAppendingPathComponent:("Cleanup At Startup")
##起動時に削除するフォルダを作成
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
# 777-->511 755-->493 700-->448 766-->502
ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidCleanupDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
#####zsh_sessionsのパス
set ocidHomeDirURL to appFileManager's homeDirectoryForCurrentUser()
set ocidSessionsDirPathURL to ocidHomeDirURL's URLByAppendingPathComponent:(".zsh_sessions")
set strSessionsDirPath to (ocidSessionsDirPathURL's |path|()) as text
####コマンド整形
set strCommandText to ("/usr/bin/touch \"" & strSessionsDirPath & "\"")
set ocidCommandText to refMe's NSString's stringWithString:(strCommandText)
set ocidTermTask to refMe's NSTask's alloc()'s init()
ocidTermTask's setLaunchPath:"/bin/zsh"
ocidTermTask's setArguments:({"-c", ocidCommandText})
set listDoneReturn to ocidTermTask's launchAndReturnError:(reference)
###現在のzsh_sessionsをゴミ箱に
set listResult to (appFileManager's trashItemAtURL:(ocidSessionsDirPathURL) resultingItemURL:(missing value) |error|:(reference))
###起動時に削除する項目にシンボリックリンクを作成する
set listResult to appFileManager's createSymbolicLinkAtURL:(ocidSessionsDirPathURL) withDestinationURL:(ocidCleanupDirPathURL) |error|:(reference)

return

|

ターミナル出力をテキストファイルに


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#com.cocolog-nifty.quicktimer.icefloe
(* Base Script
https://www.macscripter.net/t/lets-say-you-like-to-copy-text-from-terminal-app/74984
*)
#
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions
property refMe : a reference to current application

###ファイル名
set strDateNo to doGetDateNo("yyyyMMddhhmmss")
set strFileName to "ターミナル出力." & strDateNo & ".txt"


###デスクトップフォルダ に保存
set appFileManager to refMe's NSFileManager's defaultManager()
set listResponse to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidUserDesktopPathURL to (item 1 of listResponse)
###ファイルパスURL
set ocidSaveFilePathURL to ocidUserDesktopPathURL's URLByAppendingPathComponent:(strFileName) isDirectory:false
set ocidSaveFilePath to ocidSaveFilePathURL's |path|()
set strSaveFilePath to ocidSaveFilePath as text
###本処理
set strText to its doGetAttributesOfProcess("Terminal")
###戻り値をテキストエディタに展開
tell application "TextEdit"
  make new document with properties {name:strFileName, path:strSaveFilePath, text:strText}
  tell document strFileName
    activate
    ###保存して初めて確定
save in (POSIX file strSaveFilePath)
close
  end tell
  open (POSIX file strSaveFilePath)
  activate
end tell







on doGetAttributesOfProcess(argProcessName)
  tell application "System Events"
    set listAttributeName to name of attributes of process argProcessName
    
    repeat with itemAttribute in listAttributeName
      tell (attribute itemAttribute of process argProcessName)
log its value as list
log itemAttribute
      end tell
    end repeat
    
    if "AXFocusedUIElement" is in listAttributeName then
      tell value of attribute "AXFocusedUIElement" of process argProcessName
return its value
      end tell
    end if
  end tell
end doGetAttributesOfProcess





to doGetDateNo(strDateFormat)
  ####日付情報の取得
  set ocidDate to current application's NSDate's |date|()
  ###日付のフォーマットを定義
  set ocidNSDateFormatter to current application's NSDateFormatter's alloc()'s init()
ocidNSDateFormatter's setLocale:(current application's NSLocale's localeWithLocaleIdentifier:"ja_JP_POSIX")
ocidNSDateFormatter's setDateFormat:strDateFormat
  set ocidDateAndTime to ocidNSDateFormatter's stringFromDate:ocidDate
  set strDateAndTime to ocidDateAndTime as text
return strDateAndTime
end doGetDateNo


|

ManページをPDFに その2


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# Base script
# https://scriptingosx.com/2022/11/on-viewing-man-pages-ventura-update/
#
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application


##############################
#####ダイアログを前面に
##############################
tell current application
  set strName to name as text
end tell
###スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
##############################
#####クリップボードの内容取得
##############################
set ocidPasteboard to refMe's NSPasteboard's generalPasteboard()
set ocidPastBoardTypeArray to ocidPasteboard's types
set boolContain to ocidPastBoardTypeArray's containsObject:"public.utf8-plain-text"
if boolContain = true then
  set strReadString to (the clipboard as text)
else
  set boolContain to ocidPastBoardTypeArray's containsObject:"NSStringPboardType"
  if boolContain = true then
    set ocidReadString to ocidPasteboard's readObjectsForClasses:({refMe's NSString}) options:(missing value)
    set strReadString to ocidReadString as text
  else
    log "テキストなし"
    set strReadString to "COMMAND" as text
  end if
end if
set aliasIconPath to (POSIX file "/System/Applications/Utilities/Terminal.app/Contents/Resources/Terminal.icns") as alias
try
  set objResponse to (display dialog "コマンド名を入力してください" with title "入力してください" default answer strReadString buttons {"OK", "キャンセル"} default button "OK" cancel button "キャンセル" with icon aliasIconPath giving up after 10 without hidden answer)
on error
  log "エラーしました"
return "エラーしました"
  error number -128
end try
if true is equal to (gave up of objResponse) then
return "時間切れですやりなおしてください"
  error number -128
end if
if "OK" is equal to (button returned of objResponse) then
  set theResponse to (text returned of objResponse) as text
else
  log "エラーしました"
return "エラーしました"
  error number -128
end if

##############################
## Save PS dir URL
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidTempDirURL to appFileManager's temporaryDirectory()
set ocidUUID to refMe's NSUUID's alloc()'s init()
set ocidUUIDString to ocidUUID's UUIDString
set ocidSaveDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:true
### Make SaveDir
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
###Save PS
set strFileName to (theResponse & ".pdf") as text
set ocidPdfFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strFileName) isDirectory:false
set strPdfFilePath to ocidPdfFilePathURL's |path|() as text

##############################
## PS書き出して
set strCommandText to ("/usr/bin/mandoc -T pdf \"$(/usr/bin/man -w " & theResponse & ")\" > \"" & strPdfFilePath & "\"") as text
do shell script strCommandText

##プレビューで開く
set aliasPdfFilePath to (ocidPdfFilePathURL's absoluteURL()) as alias
tell application id "com.apple.Preview"
  activate
  set numWindow to count of window
  if numWindow = 0 then
    try
open file aliasPdfFilePath
    on error
      log "ここでエラー"
    end try
  else
open file aliasPdfFilePath
  end if
end tell

|

その他のカテゴリー

Accessibility Acrobat Acrobat 2020 Acrobat AddOn Acrobat Annotation Acrobat ARMDC Acrobat AV2 Acrobat BookMark Acrobat Classic Acrobat DC Acrobat Dialog Acrobat Distiller Acrobat Form Acrobat JS Acrobat Manifest Acrobat Menu Acrobat Open Acrobat Plugin Acrobat Preferences Acrobat Preflight Acrobat python Acrobat Reader Acrobat SCA Acrobat SCA Updater Acrobat Sequ Acrobat Sign Acrobat Stamps Acrobat Watermark Acrobat Windows Acrobat Windows Reader Admin Admin Account Admin Apachectl Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Mobileconfig Admin Permission Admin Pkg Admin Power Management Admin Printer Admin SetUp Admin SMB Admin Support Admin System Information Admin Tools Admin Users Admin Volumes Adobe Adobe FDKO Adobe RemoteUpdateManager AppKit Apple AppleScript AppleScript do shell script AppleScript List AppleScript ObjC AppleScript Osax AppleScript PDF AppleScript Pictures AppleScript record AppleScript Script Editor AppleScript Script Menu AppleScript Shortcuts AppleScript Shortcuts Events AppleScript System Events AppleScript System Events Plist AppleScript Video Applications AppStore Archive Attributes Automator BackUp Barcode Barcode QR Barcode QR Decode Bash Basic Basic Path Bluetooth BOX Browser Calendar CD/DVD Choose Chrome CIImage CityCode CloudStorage Color com.apple.LaunchServices.OpenWith Console Contacts CotEditor CURL current application Date&Time delimiters Desktop Device Diff Disk Dock DropBox Droplet eMail Encode % Encode Decode Encode UTF8 Error EXIFData ffmpeg File Finder Firefox Folder FolderAction Fonts GIF github Guide HTML HTML Entity Icon Illustrator Image Events Image2PDF ImageOptim iPhone iWork Javascript Jedit Json Label Leading Zero List locationd LRC lsappinfo LSSharedFileList m3u8 Mail MakePDF Map Math Media Media AVAsset Media AVconvert Media AVFoundation Media AVURLAsset Media Movie Media Music Memo Messages Microsoft Microsoft Edge Microsoft Excel Mouse Music NetWork Notes NSArray NSArray Sort NSBezierPath NSBitmapImageRep NSBundle NSCFBoolean NSCharacterSet NSColor NSColorList NSData NSDecimalNumber NSDictionary NSError NSEvent NSFileAttributes NSFileManager NSFileManager enumeratorAtURL NSFont NSFontManager NSGraphicsContext NSImage NSIndex NSKeyedArchiver NSKeyedUnarchiver NSLocale NSMutableArray NSMutableDictionary NSMutableString NSNotFound NSNumber NSOpenPanel NSPasteboard NSpoint NSPredicate NSPrintOperation NSRange NSRect NSRegularExpression NSRunningApplication NSScreen NSSize NSString NSString stringByApplyingTransform NSStringCompareOptions NSTask NSTimeZone NSURL NSURL File NSURLBookmark NSURLComponents NSURLResourceKey NSURLSession NSUserDefaults NSUUID NSView NSWorkspace Numbers OAuth OneDrive PDF PDFAnnotation PDFAnnotationWidget PDFContext PDFDisplayBox PDFDocumentPermissions PDFImageRep PDFKit PDFnUP PDFOutline perl Photoshop PlistBuddy pluginkit postalcode PostScript prefPane Preview Python QuickLook QuickTime ReadMe Regular Expression Reminders ReName Repeat RTF Safari SaveFile ScreenCapture ScreenSaver SF Symbols character id SF Symbols Entity sips Skype Slack Sound Spotlight sqlite SRT StandardAdditions Swift System Settings TCC TemporaryItems Terminal Text Text CSV Text MD Text TSV TextEdit Tools Translate Trash Twitter Typography UI Unit Conversion UTType valueForKeyPath Video VisionKit Visual Studio Code VMware Fusion Wacom webarchive webp Wifi Windows XML XML EPUB XML OPML XML Plist XML RSS XML savedSearch XML SVG XML TTML XML webloc XML XMP YouTube zoom