Keynote v12のスライド(ページ)内のタイトル(default title item)内のテキスト(object text)の強制改行を置換(削除)できないという件についての試行錯誤です。
もともと、v12以前のバージョンのKeynoteでは、LF+LFを削除することで、タイトル内のテキストの改行削除は行えていました。
ただ、同様の処理では強制改行を削除し切れないようで….
--> {"AppleSript+NSImageでよく使う 基礎的な処理一覧", "画像ファイル 変換処理", "画像回転処理", "画像ファイルからの 情報取得処理", "画像リサイズ処理", "画像フィルタ処理"}
いまひとつすっきりしません。
Keynoteのタイトル文字列をコピーして、CotEditor(文字コードをAppleScriptと同じUTF16BEに変更)の書類上にペーストすると0Ahと表示するのですが、どうもKeynote上では異なるようで困ります。
AppleScript名:Keynote v12上の選択中のスライドのタイトルをテキスト化(改行削除)(未遂).scpt |
— – Created by: Takaaki Naganoya – Created on: 2022/05/03 — – Copyright © 2022 Piyomaru Software, All Rights Reserved — use AppleScript version "2.5" use scripting additions use framework "Foundation" set repTargList to {string id 10 & string id 10, string id 10, string id 11, string id 13} –LF,CR,VTab一括置換 tell application "Keynote" tell front document set aSel to selection set aList to {} repeat with i in aSel set tmpClass to class of i if tmpClass = slide then set tmpStr0 to object text of default title item of i set hexList to retHexDumpedStr(tmpStr0) of me set tmpStr1 to (paragraphs of tmpStr0) –パラグラフごとにlistにしてみた log tmpStr1 set tmpStr2 to replaceTextMultiple(tmpStr1 as string, repTargList, "") of me as string set the end of aList to tmpStr2 end if end repeat end tell end tell return aList –文字列の前後の改行と空白文字を除去 on cleanUpText(someText) set theString to current application’s NSString’s stringWithString:someText set theString to theString’s stringByReplacingOccurrencesOfString:" +" withString:" " options:(current application’s NSRegularExpressionSearch) range:{location:0, |length|:length of someText} set theWhiteSet to current application’s NSCharacterSet’s whitespaceAndNewlineCharacterSet() set theString to theString’s stringByTrimmingCharactersInSet:theWhiteSet return theString as text end cleanUpText –指定文字列からCRLFを除去 on cleanUpCRLF(aStr) set aString to current application’s NSString’s stringWithString:aStr set bString to aString’s stringByReplacingOccurrencesOfString:(string id 10) withString:"" –remove LF set cString to bString’s stringByReplacingOccurrencesOfString:(string id 13) withString:"" –remove CR set dString to cString as string return dString end cleanUpCRLF –文字置換ルーチン on repChar(origText as string, targStr as string, repStr as string) set {txdl, AppleScript’s text item delimiters} to {AppleScript’s text item delimiters, targStr} set temp to text items of origText set AppleScript’s text item delimiters to repStr set res to temp as text set AppleScript’s text item delimiters to txdl return res end repChar –任意のデータから特定の文字列を複数パターン一括置換 on replaceTextMultiple(origData as string, origTexts as list, repText as string) set curDelim to AppleScript’s text item delimiters set AppleScript’s text item delimiters to origTexts set origData to text items of origData set AppleScript’s text item delimiters to {repText} set origData to origData as text set AppleScript’s text item delimiters to curDelim return origData end replaceTextMultiple on hexDumpString(aStr as string) set theNSString to current application’s NSString’s stringWithString:aStr set theNSData to theNSString’s dataUsingEncoding:(current application’s NSUTF8StringEncoding) set theString to (theNSData’s |debugDescription|()’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 –与えられたデータ内容をhexdumpして返す on retHexDumpedStr(aStr) set aRes to do shell script "echo " & quoted form of aStr & " | hexdump -v " return aRes end retHexDumpedStr |
More from my site
(Visited 55 times, 1 visits today)