AppleScript Applications

[kill]プロセス終了


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

#!/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 strCommandText to ("/bin/ps -alx | grep Morisawa | grep -v grep| awk '{print $2}'")
set strResponse to (do shell script strCommandText) as text
###複数ある場合対応
set AppleScript's text item delimiters to "\r"
set listPID to every text item of strResponse
set AppleScript's text item delimiters to ""
####リストの数だけ繰り返し
repeat with itemPID in listPID
  set strPID to itemPID as text
  try
    set strCommandText to ("/bin/kill -9 " & strPID & "") as text
    do shell script strCommandText
  on error
    try
      set strCommandText to ("/usr/bin/sudo /bin/kill -9 " & strPID & "") as text
      do shell script strCommandText with administrator privileges
    on error
      log "エラーがありました"
    end try
  end try
end repeat

|

XcodeのBuild先を開く


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

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

set appFileManager to refMe's NSFileManager's defaultManager()

###パス関連
set strDirPath to "~/Library/Developer/Xcode" as text
set ocidDirPathStr to refMe's NSString's stringWithString:(strDirPath)
set ocidDIrPath to ocidDirPathStr's stringByStandardizingPath()

##保存先を選択状態で開く
set ocidSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
ocidSharedWorkspace's selectFile:(ocidDIrPath) inFileViewerRootedAtPath:"/"
###Finderを前面に
set ocidRunningApplication to refMe's NSRunningApplication
set ocidAppArray to (ocidRunningApplication's runningApplicationsWithBundleIdentifier:("com.apple.finder"))
set ocidApp to ocidAppArray's firstObject()
ocidApp's activateWithOptions:(refMe's NSApplicationActivateAllWindows)

|

[mdfind]アプリケーションのバージョンを求める

AppleScript対応のアプリケーションなら

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

set strBundleID to "com.google.Chrome"
try
  tell application id strBundleID
    set strVersion to version as text
  end tell
on error
return "アプリケーションが見つかりません"
end try

log strVersion
return strVersion

appleScript非対応となると

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

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

set strBundleID to "com.apple.FontBook"

try
  tell application "Finder"
    set fileAppPath to get application file id strBundleID
  end tell
on error
  log "アプリケーションが見つかりませんmdfindで探します"
  #######################################
  ###mdfind を試す
  set strCommandText to ("/usr/bin/mdfind kMDItemCFBundleIdentifier = '" & strBundleID & "'")
  set strAppPathList to (do shell script strCommandText) as text
  ###複数インストールされている想定
  set AppleScript's text item delimiters to "\r"
  set listAppPath to every text item of strAppPathList
  set AppleScript's text item delimiters to ""
  try
    set strAppPath to (item 1 of listAppPath) as text
    set strPlistPath to ("" & strAppPath & "/Contents/Info.plist") as text
    set strCommandText to ("/usr/bin/defaults read \"" & strPlistPath & "\" \"CFBundleShortVersionString\"")
    set strVersion to (do shell script strCommandText) as text
    log strVersion
return strVersion
  on error
return "処理終了:Plistが見つかりません"
  end try
end try


set aliasAppPath to fileAppPath as alias
#######################################
###PLISTのパスを生成
tell application "Finder"
  set filePlistPath to (file "Info.plist" of folder "Contents" of aliasAppPath)
  set aliasPlistPath to filePlistPath as alias
end tell
###この方法でも同じ
set strAppPath to (POSIX path of aliasAppPath) as text
set strPlistPath to ("" & strAppPath & "Contents/Info.plist") as text
set aliasPlistFilePath to (POSIX file strPlistPath) as alias
###Plistの有無チェック
tell application "Finder"
  set boolFileExist to (exists file aliasPlistPath) as boolean
  if boolFileExist is false then
    log "Plistが見つかりません"
return "処理終了:Plistが見つかりません"
  else
    #######################################
    ### Plistの内容を取得
    tell application "System Events"
      tell contents of property list file strPlistPath
set listPlistItem to every property list item
repeat with itemPlistItem in listPlistItem
tell itemPlistItem
set strKeyName to name as text
if strKeyName is "CFBundleShortVersionString" then
set strVersion to value as text
end if
end tell
end repeat
      end tell
    end tell
  end if
end tell

log strVersion
return strVersion


|

[mdfind]アプリケーションのインストール先を求める

mdfindはスポットライト検索のインデックスが正しく引けているのが前提なので
外付けHDD等の値が取得出来ない可能性がある。
(厳密にやりたい場合は、findコマンドを利用する事になる)

通常は

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

tell application "Finder"
  try
    set fileAppPath to get application file id strBundleID
    set numCntApp to (count of fileAppPath) as integer
  on error
return "アプリケーションが見つかりません"
  end try
end tell



だが,mdfindで複数チェックする場合は

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

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

set strBundleID to "com.google.Chrome"

set strCommandText to ("/usr/bin/mdfind kMDItemCFBundleIdentifier = '" & strBundleID & "'") as text
set strAppPathList to (do shell script strCommandText) as text
set AppleScript's text item delimiters to "\r"
set listAppPath to every text item of strAppPathList
set AppleScript's text item delimiters to ""

set numCntApp to (count of listAppPath) as integer

if numCntApp > 1 then
  log "複数インストールされている"
  set listResponse to (choose from list listAppPath with title "選んでください" with prompt "処理する方を選んでください" default items (item 1 of listAppPath) OK button name "OK" cancel button name "キャンセル" without multiple selections allowed and empty selection allowed) as list
  set strAppPath to (item 1 of listResponse) as text
else
  set strAppPath to item 1 of listAppPath
end if
log strAppPath

バンドル使うと

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

#!/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.6"
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 appNSWorkspace to refMe's NSWorkspace's sharedWorkspace()

###サポートするアプリのUTI
set strUTI to "com.google.Chrome"

###バンドル
set ocidAppBundle to refMe's NSBundle's bundleWithIdentifier:(strUTI)
###インストール先の取得
if ocidAppBundle is (missing value) then
  set ocidAppBundlePathURL to appNSWorkspace's URLForApplicationWithBundleIdentifier:(strUTI)
  set ocidAppBundle to refMe's NSBundle's bundleWithURL:(ocidAppBundlePathURL)
else
  set ocidAppBundlePathURL to ocidAppBundle's bundleURL()
end if

set strFilePath to ocidAppBundlePathURL's |path| as text
set aliasFilePath to (ocidAppBundlePathURL's absoluteURL()) as alias

|

[CFBundleVersion]アプリケーションのバージョンを取得する


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

#!/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.6"
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 appNSWorkspace to refMe's NSWorkspace's sharedWorkspace()

###サポートするアプリのUTI com.google.Chrome
set strUTI to "com.adobe.Reader"

###バンドル
set ocidAppBundle to refMe's NSBundle's bundleWithIdentifier:(strUTI)
###インストール先の取得
if ocidAppBundle is (missing value) then
  set ocidAppBundlePathURL to appNSWorkspace's URLForApplicationWithBundleIdentifier:(strUTI)
  set ocidAppBundle to refMe's NSBundle's bundleWithURL:(ocidAppBundlePathURL)
end if
set ocidInfoDict to ocidAppBundle's infoDictionary
###全部見る時用
set ocidKeyArray to ocidInfoDict's allKeys()
repeat with itemKey in ocidKeyArray
  log itemKey as text
  set ocidKeyValue to (ocidInfoDict's valueForKey:(itemKey))
  log ocidKeyValue as list
end repeat
###特定のキーのみ
set ocidCFBundleVersion to (ocidInfoDict's valueForKey:("CFBundleVersion"))
log ocidCFBundleVersion as text


return ocidCFBundleVersion as text


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

#!/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.6"
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 appNSWorkspace to refMe's NSWorkspace's sharedWorkspace()

###サポートするアプリのUTI com.google.Chrome
set strUTI to "com.adobe.Reader"

###バンドル
set ocidAppBundle to refMe's NSBundle's bundleWithIdentifier:(strUTI)
###インストール先の取得
if ocidAppBundle is not (missing value) then
  set ocidAppBundlePathURL to ocidAppBundle's bundleURL()
  set strFilePath to ocidAppBundlePathURL's |path|() as text
else
  set ocidAppBundlePathURL to appNSWorkspace's URLForApplicationWithBundleIdentifier:(strUTI)
  set ocidAppBundle to refMe's NSBundle's bundleWithURL:(ocidAppBundlePathURL)
  set strFilePath to ocidAppBundlePathURL's |path|() as text
end if
###PLISTのURLを取得して
set ocidPlistPathURL to ocidAppBundlePathURL's URLByAppendingPathComponent:("Contents/Info.plist") isDirectory:false
###読み込む
set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidPlistPathURL)
set ocidBundleName to ocidPlistDict's valueForKey:("CFBundleName")
set ocidBundleVersion to ocidPlistDict's valueForKey:("CFBundleVersion")
set ocidBuild to ocidPlistDict's valueForKey:("DTSDKBuild")
set ocidShortVersionString to ocidPlistDict's valueForKey:("CFBundleShortVersionString")
###クローム用
set ocidChannelID to ocidPlistDict's valueForKey:("KSChannelID")
###Acrobat用
set ocidTrackName to ocidPlistDict's valueForKey:("TrackName")

return ocidShortVersionString as text



|

[admin]インストール済みアプリケーションのバージョンを求める


-->application file
####起動させないなら
tell application "Finder"
    set aliasAppPath to (application file id "com.tinyspeck.slackmacgap") as alias
end tell

tell application "Finder"
    set strAppPath to POSIX path of (application file id "com.tinyspeck.slackmacgap" as alias) as text
end tell

set strPlistPath to strAppPath & "Contents/Info.plist"
set strCommandText to "/usr/bin/defaults read \"" & strPlistPath & "\" CFBundleShortVersionString"
set strAppVer to do shell script strCommandText

log strAppVer
-->    (*4.29.149*)


use framework "Foundation"
use scripting additions


property refMe : a reference to current application

set strUTI to "com.google.Chrome" as text


tell application "Finder"
    set fileAppPath to application file id strUTI
    set aliasAppPath to fileAppPath as alias
    set strAppPath to POSIX path of aliasAppPath as text
end tell

set ocidAppBundle to refMe's NSBundle's bundleWithPath:strAppPath
set ocidAppName to ocidAppBundle's objectForInfoDictionaryKey:"CFBundleDisplayName"
log ocidAppName as text
-->(*Google Chrome*)


set ocidAppVer to ocidAppBundle's objectForInfoDictionaryKey:"CFBundleShortVersionString"
log ocidAppVer as text
-->(*110.0.5481.177*)

|

“XXXX.app”は壊れているため開けません。 ゴミ箱に入れる必要があります。

アプリケーションに対しての署名に問題がある場合

初回起動前に、アプリケーションに改変が行われている場合等
署名時の内容とアプリケーションのコンポーネント等の内容が異なる場合

必ずでは無いが、xattrで修正される『場合』もある

xattr -rc $HOME/Applications/XXXXX.app


起動可能になる『場合もある』

|

[AppPath]アプリケーションを探す


###この方法だと起動しちゃう

set aliasAppPath to (path to application id "com.tinyspeck.slackmacgap")
log aliasAppPath
set strAppPath to POSIX path of (path to application id "com.tinyspeck.slackmacgap")
log strAppPath


tell application "Finder"
return POSIX path of (application file id "com.tinyspeck.slackmacgap" as text)
end tell





set strAppName to "Slack.app"

set strIsregisterPath to "/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister" as text

set strResponse to (do shell script strIsregisterPath & " -dump | grep --only-matching \"/.*\\" & strAppName & "\"")

全てのアプリケーションを取得するなら

tell application "Finder" to set appNames to name of application files in entire contents of (path to applications folder)


tell application "Finder" to set appNames to name of application files in entire contents of (path to home folder)

こちらは書き方が違うだけ

set strApplicationFolderPath to (path to applications folder from local domain) as text
set strTextEditPath to strApplicationFolderPath & "TextEdit.app" as text



my posixPathTo:"TextEdit.app"

on posixPathTo:appName
set bundleID to id of application appName
tell application "Finder" to return POSIX path of (application file id bundleID as alias)
end posixPathTo:



use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

set ocidWorkSpace to current application's NSWorkspace's sharedWorkspace()

set ocidAppPath to ocidWorkSpace's URLForApplicationWithBundleIdentifier:"com.tinyspeck.slackmacgap"

set strAppFilePath to ocidAppPath's absoluteString() as text
log "strAppFilePath: " & strAppFilePath

set aliasAppPath to ocidAppPath as alias
log "aliasAppPath: " & aliasAppPath

set strAppPath to ocidAppPath's |path|() as text
log "strAppPath: " & strAppPath

|

UI Browser

UI Browser
https://pfiddlesoft.com

Mainwindowfinder

|

[AppleScript]AsHtmlizer

AsHtmlizer
http://www.script-factory.net/software/ScriptEditor/AsHtmlizer/index.html

Samplescreen_ja2x

|

より以前の記事一覧

その他のカテゴリー

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