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

カテゴリー: Text

指定のコード体系の全パターンのコードを生成 v5

Posted on 2月 21, 2018 by Takaaki Naganoya

AppleScript名:指定のコード体系の全パターンのコードを生成 v5
–v5 外部からプロパティで与えられたルールから、初期値となる「最小値」を自前で計算するように変更
–v4 桁ごとにサブルーチンを設けるのではなく、再帰処理で1つのルーチンを多重呼び出しするように変更
–v3 コードのルールを外部供給する構成にした(処理ロジックとルールの分離が完了)
–v2 各桁の最大値と最小値をプロパティで持たせるテスト
–v1 各桁のインクリメント用のサブルーチンを作成し、ルールを各サブルーチン側でハードコーディングする(正しく動く)

script spd
  property aList : {}
  
property aRuleList : {{1, 2}, {1, 3}, {0, 1}, {1, 4}, {1, 8}} –各桁の{最小値, 最大値}ペアのリスト
  
property aRuleLen : length of aRuleList
end script

set aList of spd to {} –initilaize

set initNum to getMinNum() of me –本ルール下における最小値

set the end of aList of spd to initNum

copy initNum to aNum

repeat
  set aRes to incDigit(aNum, 1) of me
  
  
if aRes = false then
    exit repeat
  end if
  
  
set the end of aList of spd to aRes
  
  
copy aRes to aNum
  
end repeat

–return length of (aList of spd)
return (aList of spd)

–与えられたルール下における最小値をルールリストから求める
on getMinNum()
  –桁数が合っているだけのダミー数字を、適切な桁数作成する(例:11111)
  
set tmpNumStr to ""
  
repeat (aRuleLen of spd) times
    set tmpNumStr to tmpNumStr & "1"
  end repeat
  
  
set tmpNum to tmpNumStr as integer
  
  
–ルールから各桁の最小値を取り出して、各桁に設定する
  
repeat with i from 1 to (aRuleLen of spd)
    set aDigNum to item 1 of item i of (aRuleList of spd)
    
set tmpNum to setDigit(tmpNum, i, aDigNum) of me
  end repeat
  
  
return tmpNum
  
end getMinNum

–繰り上がり処理(再帰呼び出しで使用)
on incDigit(aNum, aDigit)
  
  
set {thisMin, thisMax} to item ((aRuleLen of spd) – aDigit + 1) of (aRuleList of spd)
  
  
set aTarget to getDigit(aNum, aDigit) of me
  
  
if aTarget = thisMax then
    
    
if aDigit = (aRuleLen of spd) then
      –オーバーフロー(桁あふれ)エラーを返す
      
return false
    end if
    
    
set bNum to incDigit(aNum, aDigit + 1) of me
    
    
if bNum = false then return false
    
    
set bNum to setDigit(bNum, aDigit, thisMin) of me
    
  else
    
    
set aTarget to aTarget + 1
    
set bNum to setDigit(aNum, aDigit, aTarget) of me
    
  end if
  
  
return bNum
  
end incDigit

–指定数値のうち指定桁の数字を返す
on getDigit(aNum, aDigit)
  
  
set aStr to aNum as string
  
set aLen to length of aStr
  
if aLen < aDigit then
    return false –エラー
  end if
  
  
set tStr to character (aLen – aDigit + 1) of aStr
  
return tStr as integer
  
end getDigit

–指定数値のうち指定桁の数字を返す
on setDigit(aNum, aDigit, newNum)
  
  
set aStr to aNum as string
  
set aLen to length of aStr
  
if aLen < aDigit then
    return false –エラー
  end if
  
  
set aList to characters of aStr
  
  
set item (aLen – aDigit + 1) of aList to (newNum as string)
  
set aaStr to aList as string
  
  
return aaStr as integer
  
end setDigit

★Click Here to Open This Script 

Posted in recursive call Text | Tagged 10.11savvy 10.12savvy 10.13savvy | 1 Comment

FBEncryptorで文字列の暗号化、復号化

Posted on 2月 19, 2018 by Takaaki Naganoya

–> FBEncryptorKit.framework

AppleScript名:FBEncryptorで文字列の暗号化、復号化
— Created 2016-02-16 by Takaaki Naganoya
— 2016 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "FBEncryptorKit" –https://github.com/dev5tec/FBEncryptor

set aStr to "ABCDEFあいうえお
かきくけこGHIJKLMN"

set aKey to "piyomaru"

–Encryption
set aEnc to (current application’s FBEncryptorAES’s encryptBase64String:aStr keyString:aKey separateLines:true) as string
–>  "N0/E5FB97DY+qOFtfKK9CCsAMKznyej94Ons1lC90V/9vMJIaBw5R+mbaxaTm711"

–Decription
set aDec to (current application’s FBEncryptorAES’s decryptBase64String:aEnc keyString:aKey) as string
(*
"ABCDEFあいうえお
かきくけこGHIJKLMN"
*)

★Click Here to Open This Script 

Posted in Text | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

ファイルのMD5、SHA1、SHA512のハッシュ値を求める

Posted on 2月 19, 2018 by Takaaki Naganoya

–> md5Lib.framework

AppleScript名:ファイルのMD5、SHA1、SHA512のハッシュ値を求める
— Created 2016-02-11 by Takaaki Naganoya
— 2016 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "md5Lib" –https://github.com/JoeKun/FileMD5Hash

set aPath to POSIX path of (choose file)

set a to (current application’s FileHash’s md5HashOfFileAtPath:aPath) as string
–>  "329e854b9993405414c66faac0e80b86"

set b to (current application’s FileHash’s sha1HashOfFileAtPath:aPath) as string
–>  "50847286df61f304d142c6a0351e39029f010fc2"

set c to (current application’s FileHash’s sha512HashOfFileAtPath:aPath) as string
–>  "5132a7b477652db414521b36……..1a6ff240e861752c"

★Click Here to Open This Script 

Posted in Text | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

NSStringからSHA-3のハッシュ値を求める

Posted on 2月 19, 2018 by Takaaki Naganoya

–> SHA3Kit.framework

AppleScript名:NSStringからSHA-3のハッシュ値を求める
— Created 2017-08-09 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "SHA3Kit" –https://github.com/jaeggerr/NSString-SHA3

set origData to (current application’s NSString’s stringWithString:"hello")
set aHash1 to (origData’s sha3:256) as string
–> "1C8AFF950685C2ED4BC3174F3472287B56D9517B9C948127319A09A7A36DEAC8"

set aHash2 to (origData’s sha3:224) as string

set aHash3 to (origData’s sha3:384) as string

set aHash4 to (origData’s sha3:512) as string

★Click Here to Open This Script 

Posted in Text | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

NSDataからMD5値を計算する

Posted on 2月 19, 2018 by Takaaki Naganoya

–> md5FromDataKit.framework

AppleScript名:NSDataからMD5値を計算する
— Created 2016-02-11 by Takaaki Naganoya
— 2016 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "md5FromDataKit" –https://github.com/siuying/NSData-MD5

set aStr to "ぴよまるソフトウェア"
set aNSStr to current application’s NSString’s stringWithString:aStr
set aData to aNSStr’s dataUsingEncoding:(current application’s NSUTF8StringEncoding)
set aMD5Hex to (current application’s NSData’s MD5HexDigest:aData) as string
–>  "2d0b4e205f274f20b17dc8ca4870f1db"

set aMD5 to (current application’s NSData’s MD5Digest:aData)’s |description|() as string
–>  <2d0b4e20 5f274f20 b17dc8ca 4870f1db>

★Click Here to Open This Script 

Posted in Text | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

テキストをhexdump v4

Posted on 2月 19, 2018 by Takaaki Naganoya
AppleScript名:テキストをhexdump v4
— Created 2015-01-24 by Shane Stanley
— Modified 2015-01-26 by Takaaki Naganoya
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

set aStr to "あいうえお"

set theNSString to current application’s NSString’s stringWithString:aStr
set aList to hexDumpString(theNSString) of me

on hexDumpString(theNSString)
  set theNSData to theNSString’s dataUsingEncoding:(current application’s NSUTF8StringEncoding)
  
set theString to (theNSData’s |description|()’s uppercaseString())
  
  
–Remove "<" ">" characters in head and tail
  
set tLength to (theString’s |length|()) – 2
  
set aRange to current application’s NSMakeRange(1, tLength)
  
set theString2 to theString’s substringWithRange:aRange
  
  
–Replace Space Characters
  
set aString to current application’s NSString’s stringWithString:theString2
  
set bString to aString’s stringByReplacingOccurrencesOfString:" " withString:""
  
  
set aResList to splitString(bString, 2)
  
–> {​​​​​"E3", ​​​​​"81", ​​​​​"82", ​​​​​"E3", ​​​​​"81", ​​​​​"84", ​​​​​"E3", ​​​​​"81", ​​​​​"86", ​​​​​"E3", ​​​​​"81", ​​​​​"88", ​​​​​"E3", ​​​​​"81", ​​​​​"8A"​​​}
  
  
return aResList
end hexDumpString

–Split NSString in specified aNum characters
on splitString(aText, aNum)
  set aStr to current application’s NSString’s stringWithString:aText
  
if aStr’s |length|() ≤ aNum then return aText
  
  
set anArray to current application’s NSMutableArray’s new()
  
set mStr to current application’s NSMutableString’s stringWithString:aStr
  
  
set aRange to current application’s NSMakeRange(0, aNum)
  
  
repeat while (mStr’s |length|()) > 0
    if (mStr’s |length|()) < aNum then
      anArray’s addObject:(current application’s NSString’s stringWithString:mStr)
      
mStr’s deleteCharactersInRange:(current application’s NSMakeRange(0, mStr’s |length|()))
    else
      anArray’s addObject:(mStr’s substringWithRange:aRange)
      
mStr’s deleteCharactersInRange:aRange
    end if
  end repeat
  
  
return (current application’s NSArray’s arrayWithArray:anArray) as list
end splitString

★Click Here to Open This Script 

Posted in Text | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

TextEdit本文色に応じて青っぽい色は男性の音声で、赤っぽい色は女性の音声で読み上げ

Posted on 2月 16, 2018 by Takaaki Naganoya

TextEditの本文内で文字色が青っぽい色の文字は男性の音声で、赤っぽい色の文字は女性の音声で読み上げる(sayコマンド)AppleScriptです。

実行時には日本語読み上げ音声のKyokoとOtoyaをインストールしてある必要があります。インストールしてあるかどうか、対象の言語、性別で検出を行い、存在していなかった場合には読み上げを行いません。

AppleScript名:TextEdit本文色に応じて青っぽい色は男性の音声で、赤っぽい色は女性の音声で読み上げ
— Created 2018-02-15 by Takaaki Naganoya
— 2018 Piyomaru Software
use AppleScript version "2.5"
use scripting additions
use framework "Foundation"

property NSColor : a reference to current application’s NSColor
property NSArray : a reference to current application’s NSArray
property NSSortDescriptor : a reference to current application’s NSSortDescriptor

–TTS音声情報を取得する
set curLang to "ja_JP"

set v1List to getTTSVoiceNameWithLanguageAndGender(curLang, "Male") of me
if length of v1List = 0 then return
set v1 to contents of item 1 of v1List –Male Voice

set v2List to getTTSVoiceNameWithLanguageAndGender(curLang, "Female") of me
if length of v2List = 0 then return
set v2 to contents of item 1 of v2List –Female Voice

–TextEditの書類から情報を取得
set aResRec to (getTextStrAndColor() of me)
set colList to colorDat of aResRec
set strList to strList of aResRec

set aLen to length of strList

repeat with i from 1 to aLen
  set curColor to contents of item i of colList
  
set curStr to contents of item i of strList
  
set aColor to retColorDomainNameFromList(curColor, 65535) of me
  
  
if aColor = "blue" then
    –Read by Male Voice
    
say curStr using v1
  else if aColor = "red" then
    –Read by Female Voice  
    
say curStr using v2
  end if
  
end repeat

on getTextStrAndColor()
  tell application "TextEdit"
    if (count every document) = 0 then error "No Document"
    
    
tell front document
      set colList to (color of every attribute run)
      
set attList to every attribute run
    end tell
    
return {colorDat:colList, strList:attList}
  end tell
  
end getTextStrAndColor

on retCocoaColorList(aColorList, aMax)
  set cocoaColorList to {}
  
repeat with i in aColorList
    set the end of cocoaColorList to i / aMax
  end repeat
  
set the end of cocoaColorList to 1.0 –Alpha
  
return cocoaColorList
end retCocoaColorList

–数値の1D List with Recordをソート
on sort1DRecList(aList as list, aKey as string, ascendingF as boolean)
  set aArray to NSArray’s arrayWithArray:aList
  
set desc1 to NSSortDescriptor’s sortDescriptorWithKey:aKey ascending:ascendingF selector:"compare:"
  
set bList to (aArray’s sortedArrayUsingDescriptors:{desc1}) as list
  
return bList
end sort1DRecList

on getTTSVoiceNameWithLanguageAndGender(voiceLang, aGen)
  if aGen = "Male" then
    set aGender to "VoiceGenderMale"
  else if aGen = "Female" then
    set aGender to "VoiceGenderFemale"
  end if
  
  
set outArray to current application’s NSMutableArray’s new()
  
  
–Make Installed Voice List
  
set aList to current application’s NSSpeechSynthesizer’s availableVoices()
  
set bList to aList as list
  
  
repeat with i in bList
    set j to contents of i
    
set aDIc to (current application’s NSSpeechSynthesizer’s attributesForVoice:j)
    (
outArray’s addObject:aDIc)
  end repeat
  
  
set aPredicate to current application’s NSPredicate’s predicateWithFormat_("VoiceLocaleIdentifier == %@ && VoiceGender== %@", voiceLang, aGender)
  
set filteredArray to outArray’s filteredArrayUsingPredicate:aPredicate
  
set aResList to (filteredArray’s valueForKey:"VoiceName") as list
  
  
return aResList
end getTTSVoiceNameWithLanguageAndGender

on retColorDomainNameFromList(aColList as list, aColMax as integer)
  set {rNum, gNum, bNum, aNum} to retCocoaColorList(aColList, aColMax) of me
  
set aCol to NSColor’s colorWithCalibratedRed:rNum green:gNum blue:bNum alpha:aNum
  
return retColorDomainNameFronNSColor(aCol) of me
end retColorDomainNameFromList

on retColorDomainNameFronNSColor(aCol)
  set hueVal to aCol’s hueComponent()
  
set satVal to aCol’s saturationComponent()
  
set brightVal to aCol’s brightnessComponent()
  
  
if satVal ≤ 0.01 then set satVal to 0.0
  
  
set colName to ""
  
  
if satVal = 0.0 then
    if brightVal ≤ 0.2 then
      set colName to "black"
    else if (brightVal > 0.95) then
      set colName to "white"
    else
      set colName to "gray"
    end if
  else
    if hueVal ≤ (15.0 / 360) or hueVal ≥ (330 / 360) then
      set colName to "red"
    else if hueVal ≤ (45.0 / 360) then
      set colName to "orange"
    else if hueVal < (70.0 / 360) then
      set colName to "yellow"
    else if hueVal < (150.0 / 360) then
      set colName to "green"
    else if hueVal < (190.0 / 360) then
      set colName to "light blue" –cyan
    else if (hueVal < 250.0 / 360.0) then
      set colName to "blue"
    else if (hueVal < 290.0 / 360.0) then
      set colName to "purple"
    else
      set colName to "pink" –magenta
    end if
  end if
  
  
return colName
end retColorDomainNameFronNSColor

★Click Here to Open This Script 

Posted in Color Sound Text | Tagged 10.11savvy 10.12savvy 10.13savvy Sorting TextEdit | Leave a comment

テキストのキーワード検索(ファイルから読み込んで検索。複数結果対応)

Posted on 2月 15, 2018 by Takaaki Naganoya
AppleScript名:テキストの複数検索(ファイルから読み込んで検索)
— Created 2017-08-09 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

property NSString : a reference to current application’s NSString
property NSMutableArray : a reference to current application’s NSMutableArray
property NSDate : a reference to current application’s NSDate
property NSLiteralSearch : a reference to current application’s NSLiteralSearch

set aFile to POSIX path of (choose file)

set a1Dat to NSDate’s timeIntervalSinceReferenceDate()

set aStr to NSString’s stringWithContentsOfFile:aFile encoding:(current application’s NSUTF8StringEncoding) |error|:(missing value)
set aRes to searchWordRanges(aStr, "子供") of me as list
–>  {​​​​​{​​​​​​​location:1159, ​​​​​​​length:2​​​​​}, ​​​​​{​​​​​​​location:1242, ​​​​​​​length:2​​​​​}, ​​​​​{​​​​​​​location:1261, ​​​​​​​length:2​​​​​}, ​​​​​…..

set b1Dat to NSDate’s timeIntervalSinceReferenceDate()
set c1Dat to b1Dat – a1Dat

on searchWordRanges(aTargText as string, aSearchStr as string)
  set aStr to NSString’s stringWithString:aTargText
  
set bStr to NSString’s stringWithString:aSearchStr
  
  
set hitArray to NSMutableArray’s alloc()’s init()
  
set cNum to (aStr’s |length|()) as integer
  
  
set aRange to current application’s NSMakeRange(0, cNum)
  
  
repeat
    set detectedRange to aStr’s rangeOfString:bStr options:(NSLiteralSearch) range:aRange
    
if detectedRange’s location is equal to current application’s NSNotFound then exit repeat
    
    
hitArray’s addObject:detectedRange
    
    
set aNum to (detectedRange’s location) as integer
    
set bNum to (detectedRange’s |length|) as integer
    
    
set aRange to current application’s NSMakeRange(aNum + bNum, cNum – (aNum + bNum))
  end repeat
  
  
return hitArray
end searchWordRanges

★Click Here to Open This Script 

Posted in file Text | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

テキストのキーワード検索(結果をNSRangeのlistで返す)

Posted on 2月 15, 2018 by Takaaki Naganoya
AppleScript名:テキストのキーワード検索(結果をNSRangeのlistで返す)
— Created 2017-08-09 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
–http://piyocast.com/as/archives/4771

property NSString : a reference to current application’s NSString
property NSMutableArray : a reference to current application’s NSMutableArray
property NSLiteralSearch : a reference to current application’s NSLiteralSearch

set aStr to "ATGC ACGT ATGC AGTC
ATGC ACGT ATGC AGTC
ATGC ACGT ATGC AGTC
ATGC ACGT ATGC AGTC
"

set aRes to searchWordRanges(aStr, "ATGC") of me as list
–>  {​​​​​{​​​​​​​location:0, ​​​​​​​length:4​​​​​}, ​​​​​{​​​​​​​location:10, ​​​​​​​length:4​​​​​}, ​​​​​{​​​​​​​location:20, ​​​​​​​length:4​​​​​}, ​​​​​{​​​​​​​location:30, ​​​​​​​length:4​​​​​}, ​​​​​{​​​​​​​location:40, ​​​​​​​length:4​​​​​}, ​​​​​{​​​​​​​location:50, ​​​​​​​length:4​​​​​}, ​​​​​{​​​​​​​location:60, ​​​​​​​length:4​​​​​}, ​​​​​{​​​​​​​location:70, ​​​​​​​length:4​​​​​}​​​}

on searchWordRanges(aTargText as string, aSearchStr as string)
  set aStr to NSString’s stringWithString:aTargText
  
set bStr to NSString’s stringWithString:aSearchStr
  
  
set hitArray to NSMutableArray’s alloc()’s init()
  
set cNum to (aStr’s |length|()) as integer
  
  
set aRange to current application’s NSMakeRange(0, cNum)
  
  
repeat
    set detectedRange to aStr’s rangeOfString:bStr options:(NSLiteralSearch) range:aRange
    
if (detectedRange’s location) is equal to (current application’s NSNotFound) then exit repeat
    
    
hitArray’s addObject:detectedRange
    
    
set aNum to (detectedRange’s location) as integer
    
set bNum to (detectedRange’s |length|) as integer
    
    
set aRange to current application’s NSMakeRange(aNum + bNum, cNum – (aNum + bNum))
  end repeat
  
  
return hitArray
end searchWordRanges

★Click Here to Open This Script 

Posted in Text | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

stringFrom_makingIt のサンプル v2

Posted on 2月 15, 2018 by Takaaki Naganoya
AppleScript名:stringFrom_makingIt のサンプル v2
— Created 2015-01-04 by Takaaki Naganoya
— 2015 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use bPlus : script "BridgePlus" –https://www.macosxautomation.com/applescript/apps/BridgePlus.html

load framework

set res0 to current application’s SMSForder’s |description|() as text
–> "SMSForder”

–Calculates the MD5 hash of a string
set aStr to "0123456789"
set a to bPlus’s MD5From:aStr
–> "781e5e245d69b566979b86e28d23f2c7"

–Converts straight quote marks into typographer’s quote marks
set bStr to "’a’"
set b to bPlus’s smartQuotedFrom:bStr
–> "‘a’"

–Converts typographer’s quote marks into straight quote marks
set cStr to "‘a’"
set c to bPlus’s unsmartQuotedFrom:cStr
–> "’a’"

–Encodes the five reserved XML characters only
set d1Str to "&\"<>’"
set d1 to bPlus’s encodedXMLFrom:d1Str
–> "&amp;&quot;&lt;&gt;&apos;"

–Decode the five reserved XML characters only
set d2Str to "&amp;&quot;&lt;&gt;&apos;"
set d2 to bPlus’s unencodedForXMLFrom:d2Str
–> "&\"<>’"

–Encodes characters outside ASCII 32-126 in hexadecimal form (&#xHHHH;)
set eStr to "あいうえお"
set e to bPlus’s encodedHexFrom:eStr
–> "&#x3042;&#x3044;&#x3046;&#x3048;&#x304A;"

–Encodes characters outside ASCII 32-126 in decimal form (&#DD;), for use in HTML
set fStr to "あいうえお"
set f to bPlus’s encodedDecimalFrom:fStr
–> "&#12354;&#12356;&#12358;&#12360;&#12362;"

–Decodes characters that appear in decimal form (&#DD;) or hexidecimal form (&#xHHHH;), as used in XML and HTML
set gStr to "&#12354;&#12356;&#12358;&#12360;&#12362;"
set g to bPlus’s decodedDecimalFrom:gStr
–> "あいうえお"

–Deletes any paragraphs that are empty or contain only spaces and/or tabs
set hStr to "a
aaa
a

a
a

"
set h to bPlus’s emptyLineFreeFrom:hStr
–>
(*
"a
aaa
a
a
a"
*)

–Converts runs of more than one space to a single space character, and trims spaces from the beginning and end of paragraphs.
set hStr to " aaaaa bbbb ccccc "
set h to bPlus’s cleanSpacedFrom:hStr
–> "aaaaa bbbb ccccc"

★Click Here to Open This Script 

Posted in Text | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

ICUTransformのサンプル v2

Posted on 2月 15, 2018 by Takaaki Naganoya
AppleScript名:ICUTransformのサンプル v2
–Sample Code
— Created 2015-01-06 by Takaaki Naganoya
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use bPlus : script "BridgePlus" –https://www.macosxautomation.com/applescript/apps/BridgePlus.html

set theString to "ながのや, たかあき" –Hiragana
set aRes to (bPlus’s transformedFrom:theString ICUTransform:"Hiragana-Latin" inverse:false) as text
–> "naganoya, takaaki"

set theString to "ながのや, たかあき" –Hiragana
set aRes to (bPlus’s transformedFrom:theString ICUTransform:"Hiragana-Katakana" inverse:false) as text
–> "ナガノヤ, タカアキ"–Katakana

set theString to "Takaaki, Naganoya"
set aRes to (bPlus’s transformedFrom:theString ICUTransform:"Latin-Hiragana" inverse:false) as text
–> "たかあき、 ながのや"–Hiragana

set theString to "Takaaki, Naganoya"
set aRes to (bPlus’s transformedFrom:theString ICUTransform:"Latin-Katakana" inverse:false) as text
–> "タカアキ、 ナガノヤ"–Katakana

set theString to "Shane, Stanley"
set aRes to (bPlus’s transformedFrom:theString ICUTransform:"Latin-Katakana" inverse:false) as text
–> "シャネ、 スタンレイ"–Katakana…..this seems odd. "シェーン, スタンリー" will be a right spelling

set theString to "Takaaki, Naganoya"
set aRes to (bPlus’s transformedFrom:theString ICUTransform:"Halfwidth-Fullwidth" inverse:false) as text
–> "Takaaki, Naganoya"–Double Width Alphabet

set theString to "Naganoya, Takaaki"
set aRes to (bPlus’s transformedFrom:theString ICUTransform:"Latin-Hangul" inverse:false) as text
–> "나가노야, 타카아키"–Hangul

★Click Here to Open This Script 

Posted in Text | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

文字列の長さを求める

Posted on 2月 15, 2018 by Takaaki Naganoya
AppleScript名:文字列の長さを求める
— Created 2015-09-02 by Takaaki Naganoya
— 2015 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

set a to current application’s NSMutableString’s stringWithString:"あいうえお"
set b to a’s |length|()
–>  5

set c to "あいうえお"
set d to length of c
–>  5

★Click Here to Open This Script 

Posted in Text | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

considering numeric strings

Posted on 2月 15, 2018 by Takaaki Naganoya
AppleScript名:considering numeric strings
set aVer to "10.10.1"
set bVer to "10.9.5"

–OS X 10.4で導入されたconsidering numeric strings
considering numeric strings
  if aVer > bVer then
    display dialog "Yosemite is newer than Mavericks"
  else
    display dialog "Whoa!"
  end if
end considering

if aVer > bVer then
  display dialog "Yosemite is newer than Mavericks"
else
  display dialog "Whoa!"
end if

★Click Here to Open This Script 

Posted in Text | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

NSStringによりバージョン文字列比較

Posted on 2月 15, 2018 by Takaaki Naganoya
AppleScript名:NSStringによりバージョン文字列比較
— Created 2015-07-27 by Takaaki Naganoya
— 2015 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

set aVer to "10.10.0"
set bVer to "10.10"

set aVerStr to current application’s NSString’s stringWithString:aVer
set bVerStr to current application’s NSString’s stringWithString:bVer

set aRes to aVerStr’s compare:bVer options:(current application’s NSNumericSearch)
–>  1

–1:aVer > bVer, 0:aVer = bVer, -1:bVer > aVer

★Click Here to Open This Script 

Posted in Text | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

バージョン番号文字列の正確な比較

Posted on 2月 15, 2018 by Takaaki Naganoya
AppleScript名:バージョン番号文字列の正確な比較
— Created 2015-07-27 by Takaaki Naganoya
— 2015 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

set a to "10.10"
set b to "10.10.0"
set aRes to compareVersionNumericStrings(a, b) of me
–>  "A=B"

set a to "10.10"
set b to "10.10.0.1"
set aRes to compareVersionNumericStrings(a, b) of me
–>  "B>A"

set a to "10.10.1"
set b to "10.10.0.1"
set aRes to compareVersionNumericStrings(a, b) of me
–>  "A>B"

set a to "10.10.1"
set b to "10.9.1.1"
set aRes to compareVersionNumericStrings(a, b) of me
–> "A>B"

–バージョン番号文字列の正確な比較
on compareVersionNumericStrings(a, b)
  
  
set aList to parseVersionNumber(a) of me
  
–>  {​​​​​"10", ​​​​​"10"​​​}
  
  
set bList to parseVersionNumber(b) of me
  
–>  {​​​​​"10", ​​​​​"10", ​​​​​"0"​​​}
  
  
set aLen to length of aList
  
set bLen to length of bList
  
  
if aLen = bLen then
    –何もしない
    
set buryTimes to 0
  else if aLen > bLen then
    set buryTimes to (aLen – bLen)
    
set bList to addNullItems(bList, "0", buryTimes) of me
  else if bLen > aLen then
    set buryTimes to (bLen – aLen)
    
set aList to addNullItems(aList, "0", buryTimes) of me
  end if
  
  
set cLen to length of aList –aListもbListも同じ長さなのでこれでいい
  
  
repeat with i from 1 to cLen
    
    
set aItem to contents of item i of aList
    
set bItem to contents of item i of bList
    
    
considering numeric strings
      if aItem > bItem then
        return "A>B"
      else if aItem < bItem then
        return "B>A"
      end if
    end considering
    
  end repeat
  
  
return "A=B"
  
end compareVersionNumericStrings

–バージョン番号文字列からメジャーバージョンを取り出し数値として返す
on parseVersionNumber(a)
  set aStr to current application’s NSString’s stringWithString:a
  
set aRes to (aStr’s componentsSeparatedByString:".")
  
set bRes to aRes’s allObjects()
  
return bRes as list
end parseVersionNumber

–指定リストの末尾に指定個数、埋め草を追加する
on addNullItems(aList, anItem, aTimes)
  
  
copy aList to bList
  
  
repeat aTimes times
    set the end of bList to anItem
  end repeat
  
  
return bList
  
end addNullItems

★Click Here to Open This Script 

Posted in Text | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

NFKC Casefoldの影響を除外した文字列比較

Posted on 2月 15, 2018 by Takaaki Naganoya
AppleScript名:NFKC Casefoldの影響を除外した文字列比較
use AppleScript version "2.4"
use framework "Foundation"
use scripting additions

set a to "㍑"
set b to "リットル"
log (a = b) –AppleScriptネイティブの文字列比較だとこれらが混同されることに注意
–> true
set c to compStrA_B_(a, b)
–> false

set a to "バビブベボ"
set b to "ハヒフヘホ"
log (a = b)
–> false
set c to compStrA_B_(a, b)
–> false

set a to "あいうえお"
set b to "アイウエオ"
log (a = b) –AppleScriptネイティブの文字列比較だとこれらが混同されることに注意
–> true
set c to compStrA_B_(a, b)
–> false

–文字列比較をASOC(Cocoa)とAppleScriptで実施するテストルーチン
on compStrA:a b:b
  set aStr to current application’s NSString’s stringWithString:a
  
set bStr to current application’s NSString’s stringWithString:b
  
return (aStr’s isEqualToString:bStr) as boolean
end compStrA:b:

★Click Here to Open This Script 

Posted in Text | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

Umlautを無視した文字列比較(NSDiacriticInsensitiveSearch)

Posted on 2月 15, 2018 by Takaaki Naganoya
AppleScript名:Umlautを無視した文字列比較(NSDiacriticInsensitiveSearch)
— Created 2015-03-28 by Shane Stanley
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

set aRes to compareIgnoringDiacriticals("AbC", "ÂbC")
–> true

set aRes to compareIgnoringDiacriticals("Abc", "Ábc")
–> true

set aRes to compareIgnoringDiacriticals("abc", "åbc")
–> true

–Strings Compare with ignoring Umlaut
on compareIgnoringDiacriticals(aText as text, bText as text)
  set aStr to current application’s NSString’s stringWithString:aText
  
return (aStr’s compare:bText options:((current application’s NSCaseInsensitiveSearch) + (current application’s NSDiacriticInsensitiveSearch as integer))) = current application’s NSOrderedSame
end compareIgnoringDiacriticals

★Click Here to Open This Script 

Posted in Text | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

テキストからリガチャーを削除する v2

Posted on 2月 15, 2018 by Takaaki Naganoya
AppleScript名:テキストからリガチャーを削除する v2
— Created 2017-01-17 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

set inputStringWithLigatures to "ꜲꜳÆæꜴꜵꜶꜷꜸꜹꜺꜻꜼꜽffffifflfiflŒœꝎstꜨꜩᵫꝠꝡ" & "LJLjNJNjnjDZDzdzIJij"
set aRes to removeLigaturesFromString(inputStringWithLigatures) of me
–>  "AAaaAEaeAOaoAUauAVavAVavAYayffffifflfiflOEoeOOstTZtzueVYvyLJLjNJNjnjDZDzdzIJij"

on removeLigaturesFromString(inputStringWithLigatures)
  set theString to current application’s NSString’s stringWithString:inputStringWithLigatures
  
  
# Convert what may be done applying transform "ÆæffffifflfiflŒœᵫ" & "LJLjNJNjnjDZDzdzIJij"
  
set inputStringWithLigatures to (theString’s stringByApplyingTransform:"Latin-ASCII" |reverse|:false) as text
  
  
# Treat the remaining ligatures
  
set searchStrings to {"Ꜳ", "ꜳ", "Ꜵ", "ꜵ", "Ꜷ", "ꜷ", "Ꜹ", "ꜹ", "Ꜻ", "ꜻ", "Ꜽ", "ꜽ", "Ꝏ", "Ꜩ", "ꜩ", "Ꝡ", "ꝡ"} — if you find others, add them here
  
set replaceStrings to {"AA", "aa", "AO", "ao", "AU", "au", "AV", "av", "AV", "av", "AY", "ay", "OO", "TZ", "tz", "VY", "vy"} — if you find others, add them here
  
set saveTID to AppleScript’s text item delimiters
  
  
considering case
    set i to 0
    
repeat with lig in searchStrings
      set i to i + 1
      
set AppleScript’s text item delimiters to {lig}
      
set inputStringWithLigatures to text items of inputStringWithLigatures
      
set AppleScript’s text item delimiters to {item i of replaceStrings}
      
set inputStringWithLigatures to inputStringWithLigatures as text
    end repeat
  end considering
  
  
set AppleScript’s text item delimiters to saveTID
  
  
return inputStringWithLigatures
end removeLigaturesFromString

★Click Here to Open This Script 

Posted in Text | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

指定キーワードの出現回数のカウント

Posted on 2月 15, 2018 by Takaaki Naganoya
AppleScript名:指定キーワードの出現回数のカウント
set origText to "このテキストはいずれ何らかの指定キーワードが何回出現するかという見地から評価される運命にある。評価されるということは、何がしかの文法的評価体系によって分析されるということである(すんごい、いいかげんな日本語)。"
set aKeyText to "何"
set freqNum to retFrequency(origText, aKeyText) of me

–指定文字列内の指定キーワードの出現回数を取得する
on retFrequency(origText, aKeyText)
  set aRes to parseByDelim(origText, aKeyText) of me
  
return ((count every item of aRes) – 1)
end retFrequency

on parseByDelim(aData, aDelim)
  set curDelim to AppleScript’s text item delimiters
  
set AppleScript’s text item delimiters to aDelim
  
set dList to text items of aData
  
set AppleScript’s text item delimiters to curDelim
  
return dList
end parseByDelim

★Click Here to Open This Script 

Posted in Text | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

ASOCで文字を逆順に v2(CJK文字などマルチバイト対応)

Posted on 2月 15, 2018 by Takaaki Naganoya
AppleScript名:ASOCで文字を逆順に v2(CJK文字などマルチバイト対応)
— Created 2015-09-01 by Takaaki Naganoya
— Modified 2015-09-01 by Shane Stanley –Consider CJK Characters & Emoji
–http://stackoverflow.com/questions/6720191/reverse-nsstring-text
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

set aUUID to (current application’s NSUUID’s UUID()’s UUIDString()) as text
–>  "46EF17B7-CB3E-4DD9-BA8A-013D3B30A80A"

set aUUID to "😀😐" & aUUID & "😀😐"
–>  "😀😐46EF17B7-CB3E-4DD9-BA8A-013D3B30A80A😀😐"

set revUUID to reversedStr(aUUID) as text
–>  "😐😀A08A03B3D310-A8AB-9DD4-E3BC-7B71FE64😐😀"

on reversedStr(paramStr as text)
  set aStr to current application’s NSString’s stringWithString:paramStr
  
set strLength to aStr’s |length|()
  
set revStr to current application’s NSMutableString’s stringWithCapacity:strLength
  
set charIndex to strLength – 1
  
repeat while charIndex > -1
    set subStrRange to aStr’s rangeOfComposedCharacterSequenceAtIndex:charIndex
    
revStr’s appendString:(aStr’s substringWithRange:subStrRange)
    
set charIndex to (location of subStrRange) – 1
  end repeat
  
  
return revStr
end reversedStr

★Click Here to Open This Script 

Posted in Text | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

Post navigation

  • Older posts
  • Newer posts

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

Google Search

Popular posts

  • 開発機としてM2 Mac miniが来たのでガチレビュー
  • macOS 15, Sequoia
  • Pages本執筆中に、2つの書類モード切り替えに気がついた
  • Numbersで選択範囲のセルの前後の空白を削除
  • メキシカンハットの描画
  • Pixelmator Pro v3.6.4でAppleScriptからの操作時の挙動に違和感が
  • AppleScriptによる並列処理
  • macOS 15でも変化したText to Speech環境
  • Safariで「プロファイル」機能を使うとAppleScriptの処理に影響
  • デフォルトインストールされたフォント名を取得するAppleScript
  • AppleScript入門③AppleScriptを使った「自動化」とは?
  • 【続報】macOS 15.5で特定ファイル名パターンのfileをaliasにcastすると100%クラッシュするバグ
  • macOS 15 リモートApple Eventsにバグ?
  • Script Debuggerの開発と販売が2025年に終了
  • AppleScript入門① AppleScriptってなんだろう?
  • macOS 14で変更になったOSバージョン取得APIの返り値
  • NSObjectのクラス名を取得 v2.1
  • macOS 15:スクリプトエディタのAppleScript用語辞書を確認できない
  • 有害ではなくなっていたSpaces
  • AVSpeechSynthesizerで読み上げテスト

Tags

10.11savvy (1101) 10.12savvy (1242) 10.13savvy (1391) 10.14savvy (587) 10.15savvy (438) 11.0savvy (283) 12.0savvy (212) 13.0savvy (198) 14.0savvy (151) 15.0savvy (140) CotEditor (66) Finder (51) Keynote (119) NSAlert (61) NSArray (51) NSBitmapImageRep (20) NSBundle (20) NSButton (34) NSColor (53) NSDictionary (28) NSFileManager (23) NSFont (21) NSImage (41) NSJSONSerialization (21) NSMutableArray (63) NSMutableDictionary (22) NSPredicate (36) NSRunningApplication (56) NSScreen (30) NSScrollView (22) NSString (119) NSURL (98) NSURLRequest (23) NSUTF8StringEncoding (30) NSView (33) NSWorkspace (20) Numbers (76) Pages (55) Pixelmator Pro (20) Safari (44) Script Editor (27) WKUserContentController (21) WKUserScript (20) WKWebView (23) WKWebViewConfiguration (22)

カテゴリー

  • 2D Bin Packing
  • 3D
  • AirDrop
  • AirPlay
  • Animation
  • AppleScript Application on Xcode
  • Beginner
  • Benchmark
  • beta
  • Bluetooth
  • Books
  • boolean
  • bounds
  • Bug
  • Calendar
  • call by reference
  • check sum
  • Clipboard
  • Cocoa-AppleScript Applet
  • Code Sign
  • Color
  • Custom Class
  • date
  • dialog
  • diff
  • drive
  • Droplet
  • 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
  • Localize
  • Machine Learning
  • Map
  • Markdown
  • Menu
  • Metadata
  • MIDI
  • MIME
  • Natural Language Processing
  • Network
  • news
  • Noification
  • Notarization
  • Number
  • Object control
  • OCR
  • OSA
  • parallel processing
  • PDF
  • Peripheral
  • process
  • 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)
  • 未分類

アーカイブ

  • 2025年7月
  • 2025年6月
  • 2025年5月
  • 2025年4月
  • 2025年3月
  • 2025年2月
  • 2025年1月
  • 2024年12月
  • 2024年11月
  • 2024年10月
  • 2024年9月
  • 2024年8月
  • 2024年7月
  • 2024年6月
  • 2024年5月
  • 2024年4月
  • 2024年3月
  • 2024年2月
  • 2024年1月
  • 2023年12月
  • 2023年11月
  • 2023年10月
  • 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