« [Terminal]ウィンドウ設定が常にタブの場合も新規ウィンドウを開く | トップページ | [zsh]スクリプト vs code出力タブ内でのパスの文字化け »

[LETS]FontWorksのLETSアプリ起動と終了


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

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

property refMe : a reference to current application


###################################
### URLスキームから起動させる方法
set ocidURLComponents to refMe's NSURLComponents's alloc()'s init()
ocidURLComponents's setScheme:("LETS")
set ocidAppURL to ocidURLComponents's |URL|

set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
set boolDone to appSharedWorkspace's openURL:(ocidAppURL)
log boolDone
return

###################################
### SystemEventでチェックしてから起動させる方法

##バンドルID
set strBundleID to ("jp.co.fontworks.LETS") as text

tell application "System Events"
  set listBundleID to (bundle identifier of every process) as list
  set listProcess to (name of every process) as list
end tell
if listBundleID contains strBundleID then
  tell application id strBundleID
    try
      set numCntWindow to (count of every window) as integer
    on error
      set numCntWindow to 0
    end try
  end tell
else
  tell application id strBundleID to launch
  tell application id strBundleID to activate
end if



############################
### com.apple.systemevents解放
############################
set strBundleIDSystemEvent to ("com.apple.systemevents") as text
set ocidRunningApplication to refMe's NSRunningApplication
set ocidAppArray to ocidRunningApplication's runningApplicationsWithBundleIdentifier:(strBundleIDSystemEvent)
repeat with itemAppArray in ocidAppArray
itemAppArray's terminate()
end repeat

tell application "System Events" to quit


終了

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

#!/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
property refMe : a reference to current application
############################
### 設定
############################
####メインのバンドルID
set strBundleID to ("jp.co.fontworks.LETS") as text

###ヘルパーのバンドルID
set listHelperBundleID to {"jp.co.fontworks.LETS"} as list

############################
### 本処理
############################
tell application "System Events"
  set listBundleID to (bundle identifier of every process) as list
  set listProcess to (name of every process) as list
end tell
if listBundleID contains strBundleID then
  ###終了
  try
    tell application id strBundleID to quit
  end try
end if
delay 1
############################
### 半ゾンビ化対策
############################
set ocidRunningApplication to refMe's NSRunningApplication
set ocidAppArray to ocidRunningApplication's runningApplicationsWithBundleIdentifier:(strBundleID)
repeat with itemAppArray in ocidAppArray
itemAppArray's terminate()
end repeat
delay 1
############################
### ヘルパーの半ゾンビ化対策
############################
repeat with itemHelperBundleID in listHelperBundleID
  set strHelperBundleID to itemHelperBundleID as text
  #####
  set ocidRunningApplication to refMe's NSRunningApplication
  set ocidAppArray to (ocidRunningApplication's runningApplicationsWithBundleIdentifier:(strHelperBundleID))
  repeat with itemAppArray in ocidAppArray
itemAppArray's forceTerminate()
  end repeat
end repeat


|

« [Terminal]ウィンドウ設定が常にタブの場合も新規ウィンドウを開く | トップページ | [zsh]スクリプト vs code出力タブ内でのパスの文字化け »

AppleScript Fonts」カテゴリの記事