Menu

Skip to content
AppleScriptの穴
  • Home
  • Products
  • Books
  • Docs
  • Events
  • Forum
  • About This Blog
  • License
  • 仕事依頼

AppleScriptの穴

Useful & Practical AppleScript archive. Click '★Click Here to Open This Script' Link to download each AppleScript

カテゴリー: 未分類

指定バンドルIDのアプリケーションのアイコンへのパスを求める

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:指定バンドルIDのアプリケーションのアイコンへのパスを求める
— Created 2017-02-14 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"
–http://piyocast.com/as/archives/4460

set iconList to {"com.barebones.bbedit", "com.barebones.textwrangler", "com.apple.Finder"}
repeat with i in iconList
  set aPath to retIconPath(i) of me
  
if aPath is not equal to false then
    display dialog "ICNS test" with title i with icon ((POSIX file aPath) as alias) buttons {"OK"} default button 1
  end if
end repeat

–指定バンドルIDのアプリケーションのアイコンのフルパスを取得する
on retIconPath(anID)
  set aRes to chkAppIsInstalled(anID) of me
  
if aRes = false then return false
  
set appPathPOSIX to (current application’s NSWorkspace’s sharedWorkspace()’s absolutePathForAppBundleWithIdentifier:anID) as string
  
set anIconPath to getIconFilePath(appPathPOSIX) of me
  
return anIconPath
end retIconPath

–指定バンドルIDのアプリケーションが存在しているかチェック
on chkAppIsInstalled(aBundleID as string)
  set aRes to current application’s NSWorkspace’s sharedWorkspace()’s URLForApplicationWithBundleIdentifier:aBundleID
  
set bRes to (aRes is not equal to missing value)
  
return bRes
end chkAppIsInstalled

–指定ファイルのアイコンのファイルのパスを取得する
on getIconFilePath(aPOSIXPath)
  set anURL to current application’s |NSURL|’s fileURLWithPath:aPOSIXPath
  
set myBundle to current application’s NSBundle’s bundleWithURL:anURL
  
set aBundleID to myBundle’s bundleIdentifier() as text
  
set anIconFileName to (myBundle’s objectForInfoDictionaryKey:"CFBundleIconFile") as string
  
  
if anIconFileName does not end with ".icns" then
    set anIconFileName to anIconFileName & ".icns"
  end if
  
  
set ifonFileFullPath to aPOSIXPath & "/Contents/Resources/" & anIconFileName
  
return ifonFileFullPath
end getIconFilePath

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

Bundle IDからアプリケーション名称を取得する

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:Bundle IDからアプリケーション名称を取得する
— Created 2017-11-07 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"

set aBundleID to "com.apple.iWork.Keynote2"
set aRes to retNameFromBundleID(aBundleID) of me
–> "Keynote"

on retNameFromBundleID(aBundleID)
  set aURL to current application’s NSWorkspace’s sharedWorkspace()’s URLForApplicationWithBundleIdentifier:aBundleID
  
if aURL = missing value then return false –Error
  
set aBundle to current application’s NSBundle’s bundleWithURL:aURL
  
set aName to aBundle’s objectForInfoDictionaryKey:(current application’s kCFBundleExecutableKey)
  
return aName as string
end retNameFromBundleID

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

Bundle IDからアプリケーションのパスを取得する

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:Bundle IDからアプリケーションのパスを取得する
— Created 2017-11-07 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"

set aBundleID to "com.apple.iWork.Keynote"
set aRes to retPathFromBundleID(aBundleID) of me
–> "/Applications/iWork ’13/Keynote.app"

on retPathFromBundleID(aBundleID)
  set aURL to current application’s NSWorkspace’s sharedWorkspace()’s URLForApplicationWithBundleIdentifier:aBundleID
  
if aURL = missing value then return false –Error
  
return aURL’s |path|() as string
end retPathFromBundleID

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

Bundle IDからアプリケーションのURLを取得する

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:Bundle IDからアプリケーションのURLを取得する
— Created 2017-11-07 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"

set aBundleID to "com.apple.iWork.Keynote"
set aRes to retURLFromBundleID(aBundleID) of me
–> "file:///Applications/iWork%20’13/Keynote.app/"

on retURLFromBundleID(aBundleID)
  set aURL to current application’s NSWorkspace’s sharedWorkspace()’s URLForApplicationWithBundleIdentifier:aBundleID
  
if aURL = missing value then return false –Error
  
return aURL’s absoluteString() as string
end retURLFromBundleID

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

指定名称のアプリケーションのBundle IDを求める

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:指定名称のアプリケーションのBundle IDを求める
— Created 2017-11-07 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"

set anID to getBundleIDFromAppName("Keynote") of me
–>  "com.apple.iWork.Keynote"

on getBundleIDFromAppName(appName)
  set appPath to POSIX path of (path to application appName)
  
return getBundleIDFromPath(appPath) of me
end getBundleIDFromAppName

on getBundleIDFromPath(aPOSIXpath)
  set aURL to current application’s |NSURL|’s fileURLWithPath:aPOSIXpath
  
set aWorkspace to current application’s NSWorkspace’s sharedWorkspace()
  
set appURL to aWorkspace’s URLForApplicationToOpenURL:aURL
  
set aBundle to current application’s NSBundle’s bundleWithURL:appURL
  
set anID to aBundle’s bundleIdentifier()
  
return anID as string
end getBundleIDFromPath

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

指定パスのアプリケーションのBundle IDを求める

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:指定パスのアプリケーションのBundle IDを求める
— Created 2017-11-07 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"

set aFile to POSIX path of (choose file)
set anID to getBundleIDFromPath(aFile) of me
–>  "com.apple.ScriptEditor2"

on getBundleIDFromPath(aPOSIXpath)
  set aURL to current application’s |NSURL|’s fileURLWithPath:aPOSIXpath
  
set aWorkspace to current application’s NSWorkspace’s sharedWorkspace()
  
set appURL to aWorkspace’s URLForApplicationToOpenURL:aURL
  
set aBundle to current application’s NSBundle’s bundleWithURL:appURL
  
set anID to aBundle’s bundleIdentifier()
  
return anID as string
end getBundleIDFromPath

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

Bundle IDで指定したアプリケーションのローカライズ一覧を取得

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:Bundle IDで指定したアプリケーションのローカライズ一覧を取得
— Created 2017-11-07 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

set aRes to getLocalizationsFromBundleID("com.apple.Safari") of me
–>  {​​​​​"ar", ​​​​​"Base", ​​​​​"ca", ​​​​​"cs", ​​​​​"da", ​​​​​"de", ​​​​​"el", ​​​​​"en", ​​​​​"es", ​​​​​"es_419", ​​​​​"fi", ​​​​​"fr", ​​​​​"he", ​​​​​"hr", ​​​​​"hu", ​​​​​"id", ​​​​​"it", ​​​​​"ja", ​​​​​"ko", ​​​​​"ms", ​​​​​"nl", ​​​​​"no", ​​​​​"pl", ​​​​​"pt", ​​​​​"pt_PT", ​​​​​"ro", ​​​​​"ru", ​​​​​"sk", ​​​​​"sv", ​​​​​"th", ​​​​​"tr", ​​​​​"uk", ​​​​​"vi", ​​​​​"zh_CN", ​​​​​"zh_TW"​​​}

set bRes to getLocalizationsFromBundleID("com.apple.iWork.Pages") of me
–>  {​​​​​"ar", ​​​​​"Base", ​​​​​"ca", ​​​​​"cs", ​​​​​"da", ​​​​​"de", ​​​​​"el", ​​​​​"en", ​​​​​"es", ​​​​​"fi", ​​​​​"fr", ​​​​​"he", ​​​​​"hr", ​​​​​"hu", ​​​​​"id", ​​​​​"it", ​​​​​"ja", ​​​​​"ko", ​​​​​"ms", ​​​​​"nl", ​​​​​"no", ​​​​​"pl", ​​​​​"pt", ​​​​​"pt_PT", ​​​​​"ro", ​​​​​"ru", ​​​​​"sk", ​​​​​"sv", ​​​​​"th", ​​​​​"tr", ​​​​​"uk", ​​​​​"vi", ​​​​​"zh_CN", ​​​​​"zh_TW"​​​}

set cRes to getLocalizationsFromBundleID("com.adobe.Photoshop") of me
–>  {​​​​​"cs", ​​​​​"da", ​​​​​"de", ​​​​​"en-GB", ​​​​​"en", ​​​​​"English", ​​​​​"es", ​​​​​"fi", ​​​​​"fr-CA", ​​​​​"fr", ​​​​​"hu", ​​​​​"it", ​​​​​"ja", ​​​​​"ko", ​​​​​"nb", ​​​​​"nl", ​​​​​"no", ​​​​​"pl", ​​​​​"pt", ​​​​​"ru", ​​​​​"sk", ​​​​​"sv", ​​​​​"tr", ​​​​​"uk", ​​​​​"zh-Hans", ​​​​​"zh-Hant"​​​}

set dRes to getLocalizationsFromBundleID("com.adobe.InDesign") of me
–>  {​​​​​"cs", ​​​​​"da", ​​​​​"de", ​​​​​"el", ​​​​​"en", ​​​​​"en_GB", ​​​​​"English", ​​​​​"es", ​​​​​"fi", ​​​​​"fr", ​​​​​"hu", ​​​​​"it", ​​​​​"ja", ​​​​​"ko", ​​​​​"nb", ​​​​​"nl", ​​​​​"pl", ​​​​​"pt", ​​​​​"ro", ​​​​​"ru", ​​​​​"sq", ​​​​​"sv", ​​​​​"tr", ​​​​​"uk", ​​​​​"zh_CN", ​​​​​"zh_TW"​​​}

set eRes to getLocalizationsFromBundleID("com.adobe.Illustrator") of me
–>  {​​​​​"cs", ​​​​​"da", ​​​​​"de", ​​​​​"el", ​​​​​"en", ​​​​​"es", ​​​​​"fi", ​​​​​"fr", ​​​​​"hu", ​​​​​"it", ​​​​​"ja", ​​​​​"ko", ​​​​​"nl", ​​​​​"no", ​​​​​"pl", ​​​​​"pt", ​​​​​"ro", ​​​​​"ru", ​​​​​"sv", ​​​​​"tr", ​​​​​"uk", ​​​​​"zh_CN", ​​​​​"zh_TW"​​​}

on getLocalizationsFromBundleID(aBundleID)
  set aRes to retPathFromBundleID(aBundleID) of me
  
if aRes = false then error "Wrong Bundle ID."
  
return getSpecifiedAppFilesLocalizationListWithDuplication(aRes) of me
end getLocalizationsFromBundleID

–指定アプリケーションファイルの、指定Localeにおけるローカライズ言語リストを求める。重複を許容
on getSpecifiedAppFilesLocalizationListWithDuplication(appPOSIXpath)
  set aURL to (current application’s |NSURL|’s fileURLWithPath:appPOSIXpath)
  
set aBundle to current application’s NSBundle’s bundleWithURL:aURL
  
set locList to aBundle’s localizations()
  
return locList as list
end getSpecifiedAppFilesLocalizationListWithDuplication

on retPathFromBundleID(aBundleID)
  set aURL to current application’s NSWorkspace’s sharedWorkspace()’s URLForApplicationWithBundleIdentifier:aBundleID
  
if aURL = missing value then return false –Error
  
return aURL’s |path|() as string
end retPathFromBundleID

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

アプリケーションバンドル内のファイルパスを取得する

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:アプリケーションバンドル内のファイルパスを取得する
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

property |NSURL| : a reference to current application’s |NSURL|
property NSFileManager : a reference to current application’s NSFileManager

set aRes to getPathsIn_maxfiles_("/Applications/Safari.app", 4096)
–> {"/Applications/Safari.app/Contents", "/Applications/Safari.app/Contents/_CodeSignature", "/Applications/Safari.app/Contents/_CodeSignature/CodeResources", ….

— Example of file manager directory enumeration
on getPathsIn:folderPath maxfiles:MaxNum
  
  
script spd
    property aList : {}
  end script
  
  
set aList of spd to {}
  
  
set theNSURL to |NSURL|’s fileURLWithPath:folderPath
  
set theNSFileManager to NSFileManager’s new()
  
  
— get URL enumerator
  
set theNSFileEnumerator to theNSFileManager’s enumeratorAtURL:theNSURL includingPropertiesForKeys:{} options:0 errorHandler:(missing value)
  
  
repeat with i from 1 to MaxNum — arbitrary number
    — get next URL in enumerator
    
set anNSURL to theNSFileEnumerator’s nextObject()
    
if anNSURL is missing value then exit repeat — missing value means there are no more
    
    
set the end of (aList of spd) to (anNSURL’s |path|() as text)
  end repeat
  
  
return (aList of spd)
  
end getPathsIn:maxfiles:

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

指定のアプリケーションのInfo.plistの任意の属性値を取得する

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:指定のアプリケーションのInfo.plistの任意の属性値を取得する
— Created 2017-07-23 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use BridgePlus : script "BridgePlus"
–http://piyocast.com/as/archives/4759

load framework

set aP to choose file
set aURLrec to getAppPropertyFromInfoPlist(aP, "NSAppleScriptEnabled") of me
–> {appName:"Photos", appBundleID:"com.apple.Photos", urlScheme:{"photos"}}

on getAppPropertyFromInfoPlist(aP, aPropertyLabel)
  set aURL to current application’s |NSURL|’s fileURLWithPath:(POSIX path of aP)
  
set aBundle to current application’s NSBundle’s bundleWithURL:aURL
  
set aDict to aBundle’s infoDictionary()
  
  
set appNameDat to (aDict’s valueForKey:"CFBundleName") as string
  
set bundleIDat to (aDict’s valueForKey:"CFBundleIdentifier") as string
  
  
set aRes to aDict’s valueForKey:aPropertyLabel
  
if aRes is not equal to missing value then
    set aRes to aRes as string
  end if
  
set aRec to {appName:appNameDat, appBundleID:bundleIDat, propRes:aRes}
  
return aRec
end getAppPropertyFromInfoPlist

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

指定のアプリケーションのInfo.plistのすべての属性値を取得する

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:指定のアプリケーションのInfo.plistのすべての属性値を取得する
— Created 2017-07-23 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

set aP to choose file
set aURLrec to getAppAllPropertyFromInfoPlist(aP) of me
–>  (NSDictionary) {​​​​​DTCompiler:"com.apple.compilers.llvm.clang.1_0", ​​​​​NSAppleScriptEnabled:"YES", ​​​​​CFBundleInfoDictionaryVersion:"6.0", ​​​​​DTPlatformVersion:"GM", ​​​​​CFBundleIconFile:"Automator.icns", ​​​​​CFBundleName:"Automator", ​​​​​DTSDKName:"macosx10.12internal", ​​​​​NSServices:{​​​​​​​{​​​​​​​​​NSMenuItem:{​​​​​​​​​​​default:"Create Service"​​​​​​​​​}, ​​​​​​​​​NSSendTypes:{​​​​​​​​​​​"NSStringPboardType", ​​​​​​​​​​​"NSFilenamesPboardType"​​​​​​​​​}, ​​​​​​​​​…

on getAppAllPropertyFromInfoPlist(aP)
  set aURL to current application’s |NSURL|’s fileURLWithPath:(POSIX path of aP)
  
set aBundle to current application’s NSBundle’s bundleWithURL:aURL
  
set aDict to aBundle’s infoDictionary()
  
return aDict
end getAppAllPropertyFromInfoPlist

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

URLにリソースが存在するかチェック v4

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:URLにリソースが存在するかチェック v4
— Created 2016-10-18 by Takaaki Naganoya
— 2016 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

set aStr to "http://piyocast.com/as/wp-content/uploads/2018/02/map2-1024×796.png"

set aURL to (current application’s |NSURL|’s URLWithString:aStr)
set {exRes, headerRes, aData} to checkURLResourceExistence(aURL, 3) of me

log exRes
–> true / false

return {exRes, headerRes as record}
–> {true, {|content-type|:"image/png", |keep-alive|:"timeout=1, max=100", Server:"Apache", Expires:"Tue, 06 Feb 2018 09:52:20 GMT", |cache-control|:"max-age=300", |date|:"Tue, 06 Feb 2018 09:47:30 GMT", |content-length|:"323366", Connection:"Keep-Alive", |x-content-type-options|:"nosniff", Etag:"\"1f81fd7-4ef26-564871949b4c7\"", |accept-ranges|:"bytes", |last-modified|:"Tue, 06 Feb 2018 08:38:11 GMT"}}

— 指定URLにファイル(画像など)が存在するかチェック
–> {存在確認結果(boolean), レスポンスヘッダー(NSDictionary), データ(NSData)}
on checkURLResourceExistence(aURL, timeOutSec as real)
  set aRequest to (current application’s NSURLRequest’s requestWithURL:aURL cachePolicy:(current application’s NSURLRequestUseProtocolCachePolicy) timeoutInterval:timeOutSec)
  
set aRes to (current application’s NSURLConnection’s sendSynchronousRequest:aRequest returningResponse:(reference) |error|:(missing value))
  
set dRes to (first item of (aRes as list))
  
set bRes to (second item of (aRes as list))
  
if bRes is not equal to missing value then
    set hRes to (bRes’s allHeaderFields())
    
set aResCode to (bRes’s statusCode()) as integer
  else
    set hRes to {}
    
set aResCode to -1 –error
  end if
  
return {(aResCode = 200), hRes, dRes}
end checkURLResourceExistence

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy | 1 Comment

JeditΩの最前面のドキュメントのプロパティ取得

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:JeditΩの最前面のドキュメントのプロパティ取得
tell application id "jp.co.artman21.JeditOmega"
  tell front document
    properties
  end tell
end tell

–> {rich text:true, line endings:LF, path:"/Users/maro/Library/Mobile Documents/iCloud~jp~co~artman21~JeditOmega/Documents/名称未設定5.rtf", selected character range:{loc:21, len:0}, encoding:missing value, class:document, selected attribute range:{loc:2, len:0}, name:"名称未設定5", default attributes:{forecolor:{0, 0, 0}, backcolor:{65535, 65535, 65535}, charfont:"Helvetica", charsize:12.0}, modified:false, selected paragraph range:{loc:1, len:1}, selected text:"", text:"This is Test String.", document type:"リッチテキスト書式(.rtf)"}

–> {rich text:false, line endings:LF, path:"/Users/maro/Library/Mobile Documents/iCloud~jp~co~artman21~JeditOmega/Documents/名称未設定5.txt", selected character range:{loc:21, len:0}, encoding:missing value, class:document, selected attribute range:{loc:2, len:0}, name:"名称未設定5.rtf", default attributes:{forecolor:{0, 0, 0}, backcolor:{65535, 65535, 65535}, charfont:"Helvetica", charsize:12.0}, modified:false, selected paragraph range:{loc:1, len:1}, selected text:"", text:"This is Test String.", document type:"プレーンテキスト書類"}

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy JeditΩ | Leave a comment

文字種別にカウントする v2.1(JeditΩ版)

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:文字種別にカウントする v2.1(JeditΩ版)
— Created 2018-1-11 by Takaaki Naganoya
— 2018 Piyomaru Software
use AppleScript version "2.5"
use scripting additions
use framework "Foundation"
–http://piyocast.com/as/archives/5111

property NSString : a reference to current application’s NSString
property NSNumber : a reference to current application’s NSNumber
property NSDictionary : a reference to current application’s NSDictionary
property NSCountedSet : a reference to current application’s NSCountedSet
property NSMutableArray : a reference to current application’s NSMutableArray
property NSNumberFormatter : a reference to current application’s NSNumberFormatter
property NSRegularExpressionSearch : a reference to current application’s NSRegularExpressionSearch
property NSNumberFormatterRoundUp : a reference to current application’s NSNumberFormatterRoundUp

set aRes to getEditorText() of me
if aRes = false then return

set myPath to retFrontDocsPath() of me
if myPath = missing value then return

set aRec to detectCharKindRatio(aRes) of me
set bRes to retFormattedStr(aRec) of me
makeNewDocument of me given parameter:(myPath & return & return & bRes)

on detectCharKindRatio(aStr as string)
  set theCountedSet to NSCountedSet’s alloc()’s initWithArray:(characters of aStr)
  
set theEnumerator to theCountedSet’s objectEnumerator()
  
  
set cCount to 0
  
set hCount to 0
  
set kCount to 0
  
set oCount to 0
  
set lfCount to 0
  
set scCount to 0
  
set anCount to 0
  
  
set totalC to length of aStr
  
set otherList to {}
  
  
repeat
    set aValue to theEnumerator’s nextObject()
    
if aValue is missing value then exit repeat
    
    
set aStr to aValue as string
    
set tmpCount to (theCountedSet’s countForObject:aValue)
    
    
set s1Res to chkKanji(aStr) of me
    
set s2Res to chkKatakana(aStr) of me
    
set s3Res to chkHiragana(aStr) of me
    
set s4Res to chkLineFeed(aStr) of me
    
set s5Res to chkSpecialSign(aStr) of me
    
set s6Res to chkAlphaNumeric(aStr)
    
    
if s1Res = true then
      set cCount to cCount + tmpCount
    else if s2Res = true then
      set kCount to kCount + tmpCount
    else if s3Res = true then
      set hCount to hCount + tmpCount
    else if s4Res = true then
      set lfCount to lfCount + tmpCount
    else if s5Res = true then
      set scCount to scCount + tmpCount
    else if s6Res = true then
      set anCount to anCount + tmpCount
    else
      set oCount to oCount + tmpCount
      
set the end of otherList to aStr
    end if
  end repeat
  
  
set ckRes to roundingUp((cCount / totalC) * 100, 1) of me
  
set kkRes to roundingUp((kCount / totalC) * 100, 1) of me
  
set hgRes to roundingUp((hCount / totalC) * 100, 1) of me
  
set otRes to roundingUp((oCount / totalC) * 100, 1) of me
  
set lfRes to roundingUp((lfCount / totalC) * 100, 1) of me
  
set scRes to roundingUp((scCount / totalC) * 100, 1) of me
  
set anRes to roundingUp((anCount / totalC) * 100, 1) of me
  
  
return {kanjiNum:cCount, kanjiRatio:ckRes, hiraganaNum:hCount, hiraganaRatio:hgRes, katakanaNum:kCount, katakanaRatio:kkRes, otherNum:oCount, otherRatio:otRes, otherContent:otherList, lineFeedCount:lfCount, lineFeedRatio:lfRes, specialSignNum:scCount, specialSignRatio:scRes, alphaNumericNum:anCount, alphaNumericRatio:anRes, totalCount:totalC}
end detectCharKindRatio

on chkKanji(aChar)
  return detectCharKind(aChar, "[一-龠]") of me
end chkKanji

on chkHiragana(aChar)
  return detectCharKind(aChar, "[ぁ-ん]") of me
end chkHiragana

on chkKatakana(aChar)
  return detectCharKind(aChar, "[ァ-ヶ]") of me
end chkKatakana

on chkLineFeed(aChar)
  return aChar is in {string id 10, string id 13, string id 13 & string id 10}
end chkLineFeed

on chkSpecialSign(aChar)
  return aChar is in {"「", "」", "『", "』", "ー", "―", "〜", "~", "!", "?", "&", "/", "《", "》", "#", "…", "・", "♪", "。", "、", ".", "々", "“", "”", "*", "(", ")", "(", ")", " ", " ", "§", "【", "】", "■", "%", "≒"}
end chkSpecialSign

on chkAlphaNumeric(aChar)
  return detectCharKind(aChar, "[a-zA-Z0-9a-zA-Z0-9]") of me –半角全角英数字
end chkAlphaNumeric

on detectCharKind(aChar, aPattern)
  set aChar to NSString’s stringWithString:aChar
  
set searchStr to NSString’s stringWithString:aPattern
  
set matchRes to aChar’s rangeOfString:searchStr options:(NSRegularExpressionSearch)
  
if matchRes’s location() = (current application’s NSNotFound) or (matchRes’s location() as number) > 9.99999999E+8 then
    return false
  else
    return true
  end if
end detectCharKind

on roundingUp(aNum, aDigit as integer)
  set a to aNum as real
  
set aFormatter to NSNumberFormatter’s alloc()’s init()
  
aFormatter’s setMaximumFractionDigits:aDigit
  
aFormatter’s setRoundingMode:(NSNumberFormatterRoundUp)
  
set aStr to aFormatter’s stringFromNumber:(NSNumber’s numberWithFloat:a)
  
return (aStr as text) as real
end roundingUp

on getEditorText()
  tell application id "jp.co.artman21.JeditOmega"
    if (count every document) = 0 then return false
    
tell front document
      return text of it
    end tell
  end tell
end getEditorText

–処理結果から出力データの組み立て
on retFormattedStr(aRec)
  set a to "漢字  :" & (repChar("■", ((kanjiRatio of aRec) div 10)) of me & "  " & (kanjiRatio of aRec) as string) & "%" & return
  
set b to "ひらがな:" & (repChar("■", ((hiraganaRatio of aRec) div 10)) of me & "  " & (hiraganaRatio of aRec) as string) & "%" & return
  
set c to "カタカナ:" & (repChar("■", ((katakanaRatio of aRec) div 10)) of me & "  " & (katakanaRatio of aRec) as string) & "%" & return
  
set d to "改行文字:" & (repChar("■", ((lineFeedRatio of aRec) div 10)) of me & "  " & (lineFeedRatio of aRec) as string) & "%" & return
  
set e to "特殊記号:" & (repChar("■", ((specialSignRatio of aRec) div 10)) of me & "  " & (specialSignRatio of aRec) as string) & "%" & return
  
set f to "英数字 :" & (repChar("■", ((alphaNumericRatio of aRec) div 10)) of me & "  " & (alphaNumericRatio of aRec) as string) & "%" & return & return
  
set g to ("総文字数:" & encodeJapaneseNumText(totalCount of aRec) & " 文字。 400字詰め原稿用紙で約 " & ((totalCount of aRec) div 400) as string) & " 枚分" & return
  
set all to a & b & c & d & e & f & g
  
return all
end retFormattedStr

on repChar(aChar, aTimes)
  set outStr to ""
  
repeat aTimes times
    set outStr to outStr & aChar
  end repeat
  
return outStr
end repChar

–数字文字列を日本語数値表現文字列に変換
on encodeJapaneseNumText(aText as string)
  set dotText to "." as string
  
set upperDigit to ""
  
set lowerDigit to ""
  
  
–小数点の処理
  
if dotText is in aText then
    set b to offset of dotText in aText
    
set upperDigit to characters 1 thru (b – 1) of aText
    
set upperDigit to upperDigit as string
    
set lowerDigit to characters b thru -1 of aText
    
set lowerDigit to lowerDigit as string
  else
    set upperDigit to aText
  end if
  
  
set scaleList3 to {"", "万", "億", "兆", "京", "垓", "丈", "壌", "溝", "砂", "正", "載", "極", "恒河沙", "阿僧梢", "那由他", "不可思議", "無量大数"}
  
set splitDigit to 4
  
set nList to splitByDigit(upperDigit, splitDigit) of me
  
set nList to reverse of nList
  
  
set resText to ""
  
set digCount to 1
  
repeat with i in nList
    set b to (contents of i) as number
    
if b is not equal to 0 then
      set resText to (b as text) & item digCount of scaleList3 & resText
    end if
    
set digCount to digCount + 1
  end repeat
  
  
return resText & lowerDigit
  
end encodeJapaneseNumText

–指定桁数で区切る
on splitByDigit(a, splitDigit)
  set aList to characters of a
  
set aList to reverse of aList
  
  
set resList to {}
  
set tempT to ""
  
set tempC to 1
  
repeat with i in aList
    set tempT to contents of i & tempT
    
if tempC mod splitDigit = 0 then
      set resList to {tempT} & resList
      
set tempT to ""
    end if
    
set tempC to tempC + 1
  end repeat
  
  
if tempT is not equal to "" then
    set resList to {tempT} & resList
  end if
  
  
resList
  
end splitByDigit

on makeNewDocument given parameter:aStr
  tell application id "jp.co.artman21.JeditOmega"
    set aDoc to make new document with properties {text:aStr}
  end tell
end makeNewDocument

on retFrontDocsPath()
  tell application id "jp.co.artman21.JeditOmega"
    tell front document
      return path
    end tell
  end tell
end retFrontDocsPath

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy JeditΩ | Leave a comment

JeditΩで新規ドキュメント作成

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:JeditΩで新規ドキュメント作成
set aCon to "This is Test String."
set newDoc to makeNewDocumentWithJeditOmega(aCon, false) of me –make new plain text
–makeADocToPlan(newDoc) of me

on makeNewDocumentWithJeditOmega(aCon)
  tell application id "jp.co.artman21.JeditOmega"
    set aDoc to make new document with properties {text:aCon}
    
activate
    
return aDoc
  end tell
end makeNewDocumentWithJeditOmega

on makeADocToPlan(aDocRef)
  tell application id "jp.co.artman21.JeditOmega"
    tell aDocRef
      set rich text to false
    end tell
  end tell
end makeADocToPlan

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy JeditΩ | Leave a comment

各画面でムービーを全画面再生

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:各画面でムービーを全画面再生
tell application "QuickTime Player"
  activate
  
set current time of every document to 0
  
present every document
  
play every document
end tell

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy QuickTime Player | Leave a comment

QuickTime Player X経由でムービー情報を取得

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:QuickTime Player X経由でムービー情報を取得

–QuickTime Player Xでムービーの情報を取得
tell application id "com.apple.QuickTimePlayerX"
  tell document 1
    properties
    
–> {size:59828718, volume:1.0, modified:false, current audio compression:missing value, name:"戦場の絆 17_07_31 17_09 リボー・コロニー(R) 4VS4 Aクラス.mp4", current microphone:missing value, output muted:false, duration:305.203077777778, current movie compression:missing value, current screen compression:missing value, data rate:196029, current camera:missing value, preview resolution:false, playing:true, class:document, file:file "Cherry:Users:me:Movies:戦場の絆 17_07_31 17_09 リボー・コロニー(R) 4VS4 Aクラス.mp4", natural dimensions:{1280, 720}, looping:false, time:1.6761711, rate:1.0}
  end tell
end tell

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy QuickTime Player | Leave a comment

QuickTime Player Xで録音を開始する

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:QuickTime Player Xで録音を開始する
tell application id "com.apple.QuickTimePlayerX"
  set recSound to (new audio recording)
  
  
tell recSound
    start
  end tell
end tell

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy QuickTime Player | Leave a comment

QuickTimeムービーの縦横ドット数を取得する

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:QuickTimeムービーの縦横ドット数を取得する
tell application "QuickTime Player"
  tell document 1
    set {aWidth, aHeight} to natural dimensions
  end tell
end tell
–>{640, 480}

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy QuickTime Player | Leave a comment

QT Playerでムービー再生位置を先頭に(巻き戻し)

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:QT Playerでムービー再生位置を先頭に(巻き戻し)
tell application "QuickTime Player"
  tell document 1
    set current time to 0
  end tell
end tell

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy QuickTime Player | Leave a comment

オープン中のムービーのファイルにラベルを付ける

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:オープン中のムービーのファイルにラベルを付ける
— Created 2017-10-26 by Takaaki Naganoya
— 2017 Piyomaru Software
–http://piyocast.com/as/archives/4925
tell application "QuickTime Player"
  set aDocList to every document
end tell

repeat with i in aDocList
  
  
tell application "QuickTime Player"
    tell i
      set aProp to properties
      
set aFile to (file of aProp) as alias
    end tell
  end tell
  
  
tell application "Finder"
    set label index of aFile to 5
  end tell
  
end repeat

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy QuickTime Player | Leave a comment

Post navigation

  • Older posts
  • Newer posts

電子書籍(PDF)をオンラインストアで販売中!

Google Search

Popular posts

  • macOS 13, Ventura(継続更新)
  • アラートダイアログ上にWebViewで3Dコンテンツを表示(WebGL+three.js)v3
  • Xcode 14.2でAppleScript App Templateを復活させる
  • macOS 13 TTS Voice環境に変更
  • UI Browserがgithub上でソース公開され、オープンソースに
  • 2022年に書いた価値あるAppleScript
  • ChatGPTで文章のベクトル化(Embedding)
  • 新発売:AppleScriptからSiriを呼び出そう!
  • iWork 12.2がリリースされた
  • 従来と異なるmacOS 13の性格?
  • 新発売:CotEditor Scripting Book with AppleScript
  • macOS 13対応アップデート:AppleScript実践的テクニック集(1)GUI Scripting
  • macOS 13でNSNotFoundバグふたたび
  • ChatGPTでchatに対する応答文を取得
  • 新発売:iWork Scripting Book with AppleScript
  • Finderの隠し命令openVirtualLocationが発見される
  • macOS 13.1アップデートでスクリプトエディタの挙動がようやくまともに
  • あのコン過去ログビューワー(暫定版)
  • AppleScriptの数値変数で指数表示にならない最大値、最小値
  • バカスタム App選手権 入賞!

Tags

10.11savvy (1101) 10.12savvy (1242) 10.13savvy (1390) 10.14savvy (586) 10.15savvy (434) 11.0savvy (277) 12.0savvy (186) 13.0savvy (59) CotEditor (60) Finder (47) iTunes (19) Keynote (99) NSAlert (60) NSArray (51) NSBezierPath (18) NSBitmapImageRep (20) NSBundle (20) NSButton (34) NSColor (51) NSDictionary (27) NSFileManager (23) NSFont (18) NSImage (41) NSJSONSerialization (21) NSMutableArray (62) NSMutableDictionary (21) NSPredicate (36) NSRunningApplication (56) NSScreen (30) NSScrollView (22) NSString (117) NSURL (97) NSURLRequest (23) NSUTF8StringEncoding (30) NSView (33) NSWorkspace (20) Numbers (57) Pages (38) Safari (41) Script Editor (20) WKUserContentController (21) WKUserScript (20) WKUserScriptInjectionTimeAtDocumentEnd (18) WKWebView (23) WKWebViewConfiguration (22)

カテゴリー

  • 2D Bin Packing
  • 3D
  • AirDrop
  • AirPlay
  • Animation
  • AppleScript Application on Xcode
  • beta
  • Bluetooth
  • Books
  • boolean
  • bounds
  • Bug
  • Calendar
  • call by reference
  • Clipboard
  • Code Sign
  • Color
  • Custom Class
  • dialog
  • drive
  • exif
  • file
  • File path
  • filter
  • folder
  • Font
  • Font
  • GAME
  • geolocation
  • GUI
  • GUI Scripting
  • Hex
  • History
  • How To
  • iCloud
  • Icon
  • Image
  • Input Method
  • Internet
  • iOS App
  • JavaScript
  • JSON
  • JXA
  • Keychain
  • Keychain
  • Language
  • Library
  • list
  • Locale
  • Machine Learning
  • Map
  • Markdown
  • Menu
  • Metadata
  • MIDI
  • MIME
  • Natural Language Processing
  • Network
  • news
  • Noification
  • Notarization
  • Number
  • Object control
  • OCR
  • OSA
  • PDF
  • Peripheral
  • PRODUCTS
  • QR Code
  • Raw AppleEvent Code
  • Record
  • rectangle
  • recursive call
  • regexp
  • Release
  • Remote Control
  • Require Control-Command-R to run
  • REST API
  • Review
  • RTF
  • Sandbox
  • Screen Saver
  • Script Libraries
  • sdef
  • search
  • Security
  • selection
  • shell script
  • Shortcuts Workflow
  • Sort
  • Sound
  • Spellchecker
  • Spotlight
  • SVG
  • System
  • Tag
  • Telephony
  • Text
  • Text to Speech
  • timezone
  • Tools
  • Update
  • URL
  • UTI
  • Web Contents Control
  • WiFi
  • XML
  • XML-RPC
  • イベント(Event)
  • 未分類

アーカイブ

  • 2023年9月
  • 2023年8月
  • 2023年7月
  • 2023年6月
  • 2023年5月
  • 2023年4月
  • 2023年3月
  • 2023年2月
  • 2023年1月
  • 2022年12月
  • 2022年11月
  • 2022年10月
  • 2022年9月
  • 2022年8月
  • 2022年7月
  • 2022年6月
  • 2022年5月
  • 2022年4月
  • 2022年3月
  • 2022年2月
  • 2022年1月
  • 2021年12月
  • 2021年11月
  • 2021年10月
  • 2021年9月
  • 2021年8月
  • 2021年7月
  • 2021年6月
  • 2021年5月
  • 2021年4月
  • 2021年3月
  • 2021年2月
  • 2021年1月
  • 2020年12月
  • 2020年11月
  • 2020年10月
  • 2020年9月
  • 2020年8月
  • 2020年7月
  • 2020年6月
  • 2020年5月
  • 2020年4月
  • 2020年3月
  • 2020年2月
  • 2020年1月
  • 2019年12月
  • 2019年11月
  • 2019年10月
  • 2019年9月
  • 2019年8月
  • 2019年7月
  • 2019年6月
  • 2019年5月
  • 2019年4月
  • 2019年3月
  • 2019年2月
  • 2019年1月
  • 2018年12月
  • 2018年11月
  • 2018年10月
  • 2018年9月
  • 2018年8月
  • 2018年7月
  • 2018年6月
  • 2018年5月
  • 2018年4月
  • 2018年3月
  • 2018年2月

https://piyomarusoft.booth.pm/items/301502

メタ情報

  • ログイン
  • 投稿フィード
  • コメントフィード
  • WordPress.org

Forum Posts

  • 人気のトピック
  • 返信がないトピック

メタ情報

  • ログイン
  • 投稿フィード
  • コメントフィード
  • WordPress.org
Proudly powered by WordPress
Theme: Flint by Star Verte LLC