AppleScript Barcode

[CIPDF417BarcodeGenerator]PDF417バーコードを作成する

基本はQRと同じ
値は仕様を参照



#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#webViewベーススクリプト
#https://macscripter.net/viewtopic.php?pid=209146
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use framework "WebKit"
use scripting additions

property objMe : a reference to current application
property objNSURL : a reference to objMe's NSURL
property objNSString : a reference to objMe's NSString
set objFileManager to objMe's NSFileManager's defaultManager()

#####################################
set aliasIconPath to POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/BookmarkIcon.icns" as alias
set theResponse to "Hello worldsABCDEFG1234" as text
try
set objResponse to (display dialog "数値のみ48桁まで" with title "PDF417コードを作成します" default answer theResponse buttons {"OK", "キャンセル"} default button "OK" cancel button "キャンセル" with icon aliasIconPath giving up after 20 without hidden answer)
on error
log "エラーしました"
return
end try
if true is equal to (gave up of objResponse) then
return "時間切れですやりなおしてください"
end if
if "OK" is equal to (button returned of objResponse) then
set strText to (text returned of objResponse) as text
else
return "キャンセル"
end if
###フォルダのパス
###ピクチャーフォルダのパス
set aliasDirPath to (path to pictures folder from user domain) as alias
set strDirPath to POSIX path of aliasDirPath as text
####フォルダ名
set strFolderName to "QRcode" as text
set strDirPath to ("" & strDirPath & strFolderName & "") as text
###NSStringテキスト
set ocidDirPath to objNSString's stringWithString:strDirPath
###フォルダを作る
###途中のフォルダも作る-->true
set boolMakeNewFolder to (objFileManager's createDirectoryAtPath:ocidDirPath withIntermediateDirectories:true attributes:(missing value) |error|:(missing value))

####日付フォーマット
set prefDateFormat to "yyyyMMddHHmmss"
set ocidFormatter to objMe's NSDateFormatter's alloc()'s init()
ocidFormatter's setLocale:(objMe's NSLocale's localeWithLocaleIdentifier:"ja_JP_POSIX")
ocidFormatter's setDateFormat:(prefDateFormat as string)
set strDateAndTime to (ocidFormatter's stringFromDate:(current date)) as text
#####日付をファイル名にする
set strSaveFilePath to strDirPath & "/" & strDateAndTime & ".png"

#####################################
set strInputText to (strText) as text
####テキストをNSString
set ocidInputString to objNSString's stringWithString:strInputText
#####################################
##全角を半角に変換して
set ocidInputStringHalfwidth to (ocidInputString's stringByApplyingTransform:(objMe's NSStringTransformFullwidthToHalfwidth) |reverse|:false)
##制御文字取り除き
set ocidwhitespaceAndNewlineCharacterSet to objMe's NSCharacterSet's whitespaceAndNewlineCharacterSet
set ocidInputString to ocidInputStringHalfwidth's stringByTrimmingCharactersInSet:ocidwhitespaceAndNewlineCharacterSet
##スペース取り除き
set ocidSearchString to objNSString's stringWithString:" "
set ocidReplacementString to objNSString's stringWithString:""
set ocidTrimmingText to ocidInputString's stringByReplacingOccurrencesOfString:ocidSearchString withString:ocidReplacementString
##ハイフン取り除き
set ocidSearchString to objNSString's stringWithString:"-"
set ocidTrimmingText to ocidTrimmingText's stringByReplacingOccurrencesOfString:ocidSearchString withString:ocidReplacementString
#####################################
####テキストをUTF8
set ocidUtf8InputString to ocidTrimmingText's dataUsingEncoding:(objMe's NSUTF8StringEncoding)
####CIPDF417BarcodeGenerator初期化
set ocidPDF417Image to objMe's CIFilter's filterWithName:"CIPDF417BarcodeGenerator"
ocidPDF417Image's setDefaults()
###設定
ocidPDF417Image's setValue:ocidUtf8InputString forKey:"inputMessage"
###BOOLEAN
ocidPDF417Image's setValue:"false" forKey:"inputAlwaysSpecifyCompaction"
ocidPDF417Image's setValue:"true" forKey:"inputCompactStyle"
##Number. Min: 0.0 Max: 3.0
ocidPDF417Image's setValue:"3.0" forKey:"inputCompactionMode"
##Number. Min: 0.0 Max: 8.0
ocidPDF417Image's setValue:"3.0" forKey:"inputCorrectionLevel"
##Number. Min: 1.0 Max: 30.0
ocidPDF417Image's setValue:"5" forKey:"inputDataColumns"
##Number. Min: 3.0 Max: 90.0
ocidPDF417Image's setValue:"10" forKey:"inputRows"
##Number. Min: 13.0 Max: 283.0
ocidPDF417Image's setValue:"100" forKey:"inputMaxHeight"
##Number. Min: 56.0 Max: 583.0
ocidPDF417Image's setValue:"480" forKey:"inputMaxWidth"
##Number. Min: 13.0 Max: 283.0
ocidPDF417Image's setValue:"100" forKey:"inputMinHeight"
##Number. Min: 56.0 Max: 583.0
ocidPDF417Image's setValue:"100" forKey:"inputMinWidth"
##Number. Min: 0.0
ocidPDF417Image's setValue:"1" forKey:"inputPreferredAspectRatio"

###PDF417コード本体のイメージ
set ocidCIImage to ocidPDF417Image's outputImage()
log ocidCIImage
log className() of ocidCIImage as text

-->ここで生成されるのはPDF417は一番細いライン幅1pxの最小サイズ
###PDF417コードの縦横取得
set ocidCIImageDimension to ocidCIImage's extent()
set ocidCIImageWidth to (item 1 of item 2 of ocidCIImageDimension) as integer
set ocidCIImageHight to (item 2 of item 2 of ocidCIImageDimension) as integer
###最終的に出力したいpxサイズ
set numScaleMax to 580
###整数で拡大しないとアレなのでの値のニアなサイズになります
set numWidth to ((numScaleMax / ocidCIImageWidth) div 1) as integer
set numHight to (((580 / 2) / ocidCIImageHight) div 1) as integer
###↑サイズの拡大縮小する場合はここで値を調整すれば良い
####変換スケール作成-->拡大
set recordScalse to objMe's CGAffineTransform's CGAffineTransformMakeScale(numWidth, numHight)
##変換スケールを適応(元のサイズに元のサイズのスケール適応しても意味ないけど
set ocidCIImageScaled to ocidCIImage's imageByApplyingTransform:recordScalse
#######元のセルが1x1pxの最小サイズで出したいときはここで処理
##set ocidCIImageScaled to ocidCIImage
###イメージデータを展開
set ocidNSCIImageRep to objMe's NSCIImageRep's imageRepWithCIImage:ocidCIImageScaled
###出力用のイメージの初期化
set ocidNSImageScaled to objMe's NSImage's alloc()'s initWithSize:(ocidNSCIImageRep's |size|())
###イメージデータを合成
ocidNSImageScaled's addRepresentation:ocidNSCIImageRep
###出来上がったデータはOS_dispatch_data
set ocidOsDispatchData to ocidNSImageScaled's TIFFRepresentation()
####NSBitmapImageRep
set ocidNSBitmapImageRep to objMe's NSBitmapImageRep's imageRepWithData:ocidOsDispatchData
#####################################
###quiet zone用に画像をパディングする
set numPadWidth to ((ocidCIImageWidth * numWidth) + (numWidth * 6)) as integer
set numPadHight to ((ocidCIImageHight * numHight) + (numHight * 6)) as integer
###左右に4セル分づつ余白 quiet zoneを足す
####まずは元のコードのサイズに8セルサイズ分足したサイズの画像を作って
set ocidNSBitmapImagePadRep to (objMe's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:numPadWidth pixelsHigh:numPadHight bitsPerSample:8 samplesPerPixel:4 hasAlpha:true isPlanar:false colorSpaceName:(objMe's NSCalibratedRGBColorSpace) bitmapFormat:(objMe's NSAlphaFirstBitmapFormat) bytesPerRow:0 bitsPerPixel:32)
###初期化
objMe's NSGraphicsContext's saveGraphicsState()
###ビットマップイメージ
(objMe's NSGraphicsContext's setCurrentContext:(objMe's NSGraphicsContext's graphicsContextWithBitmapImageRep:ocidNSBitmapImagePadRep))
###塗り色を『白』に指定して
objMe's NSColor's whiteColor()'s |set|()
###画像にする
objMe's NSRectFill({origin:{x:0, y:0}, |size|:{width:numPadWidth, height:numPadHight}})
###出来上がった画像にバーコードを左右3セル分ずらした位置にCompositeSourceOverする
ocidNSBitmapImageRep's drawInRect:{origin:{x:(numWidth * 3), y:(numHight * 3)}, |size|:{width:numPadWidth, Hight:numPadHight}} fromRect:{origin:{x:0, y:0}, |size|:{width:numPadWidth, height:numPadHight}} operation:(objMe's NSCompositeSourceOver) fraction:1.0 respectFlipped:true hints:(missing value)
####画像作成終了
objMe's NSGraphicsContext's restoreGraphicsState()

#####################################
####JPEG用の圧縮プロパティ
##set ocidNSSingleEntryDictionary to objMe's NSDictionary's dictionaryWithObject:1 forKey:(objMe's NSImageCompressionFactor)
####PNG用の圧縮プロパティ
set ocidNSSingleEntryDictionary to objMe's NSDictionary's dictionaryWithObject:true forKey:(objMe's NSImageInterlaced)

#####出力イメージへ変換
set ocidNSInlineData to (ocidNSBitmapImagePadRep's representationUsingType:(objMe's NSBitmapImageFileTypePNG) |properties|:ocidNSSingleEntryDictionary)
(*
NSBitmapImageFileTypeJPEG
NSBitmapImageFileTypePNG
NSBitmapImageFileTypeGIF
NSBitmapImageFileTypeBMP
NSBitmapImageFileTypeTIFF
NSBitmapImageFileTypeJPEG2000
*)
######インラインデータをファイルに書き出し
set boolMakePDF417 to (ocidNSInlineData's writeToFile:strSaveFilePath atomically:true)



set aliasDirPath to POSIX file strDirPath as alias

tell application "Finder"

select aliasDirPath
activate
end tell


return

#####################################
set targetURL to ("file://" & strSaveFilePath & "") as text
#####################################
repeat 1 times
####NSMutableDictionaryの初期化
set ocidNSDictionaryM to objMe's NSMutableDictionary's dictionary()
####ウィンドのサイズ
set {numWidth, numHeight} to {600, 300}
tell ocidNSDictionaryM
####画像のパス
its setObject:targetURL forKey:"theURL"
####ウィンドのサイズ
its setObject:numWidth forKey:"width"
its setObject:numHeight forKey:"height"
end tell
if objMe's NSThread's isMainThread() as boolean then
####Webビューを表示する
my performWebView:ocidNSDictionaryM
else
my performSelectorOnMainThread:"performWebView:" withObject:ocidNSDictionaryM waitUntilDone:true
end if
tell ocidNSDictionaryM
activate
end tell
#####10秒間開いたら閉じる
#####ここでこの処理をしたのはスクリプトメニューからの実行を配慮して
delay 10
end repeat



on performWebView:ocidNSDictionaryM
set {width, height} to {ocidNSDictionaryM's objectForKey:"width", ocidNSDictionaryM's objectForKey:"height"}
set strURL to (ocidNSDictionaryM's objectForKey:"theURL")
########
set theConfiguration to objMe's WKWebViewConfiguration's alloc()'s init()
set ocidURL to objNSURL's URLWithString:strURL
set theFetch to objNSString's stringWithContentsOfURL:ocidURL encoding:(objMe's NSUTF8StringEncoding) |error|:(missing value)
set theUserScript to objMe's WKUserScript's alloc()'s initWithSource:theFetch injectionTime:(objMe's WKUserScriptInjectionTimeAtDocumentEnd) forMainFrameOnly:true
set theUserContentController to objMe's WKUserContentController's alloc()'s init()
theUserContentController's addUserScript:theUserScript
theConfiguration's setUserContentController:theUserContentController
set webViewSize to objMe's NSMakeRect(0, 0, width, height)
set webView to objMe's WKWebView's alloc()'s initWithFrame:webViewSize configuration:theConfiguration
webView's setNavigationDelegate:me
webView's setUIDelegate:me
webView's setTranslatesAutoresizingMaskIntoConstraints:true
set theURL to objMe's |NSURL|'s URLWithString:strURL
set theRequest to objMe's NSURLRequest's requestWithURL:theURL
webView's loadRequest:theRequest
set ocidWebView to webView
########
set listWindowSize to objMe's NSMakeRect(0, 0, width, height)
set numStyleMaskNo to (objMe's NSWindowStyleMaskTitled as integer)
set numStyleMaskNo to numStyleMaskNo + (objMe's NSWindowStyleMaskClosable as integer)
set numStyleMaskNo to numStyleMaskNo + (objMe's NSWindowStyleMaskMiniaturizable as integer)
set numStyleMaskNo to numStyleMaskNo + (objMe's NSWindowStyleMaskResizable as integer)
set ocidWindow to objMe's NSWindow's alloc()'s initWithContentRect:listWindowSize styleMask:numStyleMaskNo backing:2 defer:yes
########
ocidWindow's setContentView:ocidWebView
set ocidNSWindowController to objMe's NSWindowController's alloc()'s initWithWindow:ocidWindow
ocidNSWindowController's showWindow:me
ocidNSWindowController's |window|'s |center|()
ocidNSWindowController's |window|'s makeKeyAndOrderFront:me
tell ocidNSDictionaryM to its setObject:ocidWindow forKey:"window"
end performWebView:

|

[CICode128BarcodeGenerator]Code128バーコード作成

基本はQRコードと同じ


#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#webViewベーススクリプト
#https://macscripter.net/viewtopic.php?pid=209146
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use framework "WebKit"
use scripting additions

property objMe : a reference to current application
property objNSURL : a reference to objMe's NSURL
property objNSString : a reference to objMe's NSString
set objFileManager to objMe's NSFileManager's defaultManager()

#####################################
set aliasIconPath to POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/BookmarkIcon.icns" as alias
set theResponse to "1234567890" as text
try
set objResponse to (display dialog "数値のみ48桁まで" with title "code128コードを作成します" default answer theResponse buttons {"OK", "キャンセル"} default button "OK" cancel button "キャンセル" with icon aliasIconPath giving up after 20 without hidden answer)
on error
log "エラーしました"
return
end try
if true is equal to (gave up of objResponse) then
return "時間切れですやりなおしてください"
end if
if "OK" is equal to (button returned of objResponse) then
set strText to (text returned of objResponse) as text
else
return "キャンセル"
end if
###フォルダのパス
###ピクチャーフォルダのパス
set aliasDirPath to (path to pictures folder from user domain) as alias
set strDirPath to POSIX path of aliasDirPath as text
####フォルダ名
set strFolderName to "QRcode" as text
set strDirPath to ("" & strDirPath & strFolderName & "") as text
###NSStringテキスト
set ocidDirPath to objNSString's stringWithString:strDirPath
###フォルダを作る
###途中のフォルダも作る-->true
set boolMakeNewFolder to (objFileManager's createDirectoryAtPath:ocidDirPath withIntermediateDirectories:true attributes:(missing value) |error|:(missing value))

####日付フォーマット
set prefDateFormat to "yyyyMMddHHmmss"
set ocidFormatter to objMe's NSDateFormatter's alloc()'s init()
ocidFormatter's setLocale:(objMe's NSLocale's localeWithLocaleIdentifier:"ja_JP_POSIX")
ocidFormatter's setDateFormat:(prefDateFormat as string)
set strDateAndTime to (ocidFormatter's stringFromDate:(current date)) as text
#####日付をファイル名にする
set strSaveFilePath to strDirPath & "/" & strDateAndTime & ".png"

#####################################
set strInputText to (strText) as text
####テキストをNSString
set ocidInputString to objNSString's stringWithString:strInputText
#####################################
##全角を半角に変換して
set ocidInputStringHalfwidth to (ocidInputString's stringByApplyingTransform:(objMe's NSStringTransformFullwidthToHalfwidth) |reverse|:false)
##制御文字取り除き
set ocidwhitespaceAndNewlineCharacterSet to objMe's NSCharacterSet's whitespaceAndNewlineCharacterSet
set ocidInputString to ocidInputStringHalfwidth's stringByTrimmingCharactersInSet:ocidwhitespaceAndNewlineCharacterSet
##スペース取り除き
set ocidSearchString to objNSString's stringWithString:" "
set ocidReplacementString to objNSString's stringWithString:""
set ocidTrimmingText to ocidInputString's stringByReplacingOccurrencesOfString:ocidSearchString withString:ocidReplacementString
##ハイフン取り除き
set ocidSearchString to objNSString's stringWithString:"-"
set ocidTrimmingText to ocidTrimmingText's stringByReplacingOccurrencesOfString:ocidSearchString withString:ocidReplacementString
#####################################
####テキストをUTF8
set ocidUtf8InputString to ocidTrimmingText's dataUsingEncoding:(objMe's NSUTF8StringEncoding)
####CICode128Generator初期化
set ocidCode128Image to objMe's CIFilter's filterWithName:"CICode128BarcodeGenerator"
ocidCode128Image's setDefaults()
###テキスト設定
ocidCode128Image's setValue:ocidUtf8InputString forKey:"inputMessage"
###QuietSpace
ocidCode128Image's setValue:"4.0" forKey:"inputQuietSpace"
###inputBarcodeHeight
ocidCode128Image's setValue:"12.0" forKey:"inputBarcodeHeight"
###Code128コード本体のイメージ
set ocidCIImage to ocidCode128Image's outputImage()
-->ここで生成されるのはCode128は一番細いライン幅1pxの最小サイズ
###Code128コードの縦横取得
set ocidCIImageDimension to ocidCIImage's extent()
set ocidCIImageWidth to (item 1 of item 2 of ocidCIImageDimension) as integer
set ocidCIImageHight to (item 2 of item 2 of ocidCIImageDimension) as integer
###最終的に出力したいpxサイズ
set numScaleMax to 580
###整数で拡大しないとアレなのでの値のニアなサイズになります
set numWidth to ((numScaleMax / ocidCIImageWidth) div 1) as integer
set numHight to (((580 / 2) / ocidCIImageHight) div 1) as integer
###↑サイズの拡大縮小する場合はここで値を調整すれば良い
####変換スケール作成-->拡大
set recordScalse to objMe's CGAffineTransform's CGAffineTransformMakeScale(numWidth, numHight)
##変換スケールを適応(元のサイズに元のサイズのスケール適応しても意味ないけど
set ocidCIImageScaled to ocidCIImage's imageByApplyingTransform:recordScalse
#######元のセルが1x1pxの最小サイズで出したいときはここで処理
##set ocidCIImageScaled to ocidCIImage
###イメージデータを展開
set ocidNSCIImageRep to objMe's NSCIImageRep's imageRepWithCIImage:ocidCIImageScaled
###出力用のイメージの初期化
set ocidNSImageScaled to objMe's NSImage's alloc()'s initWithSize:(ocidNSCIImageRep's |size|())
###イメージデータを合成
ocidNSImageScaled's addRepresentation:ocidNSCIImageRep
###出来上がったデータはOS_dispatch_data
set ocidOsDispatchData to ocidNSImageScaled's TIFFRepresentation()
####NSBitmapImageRep
set ocidNSBitmapImageRep to objMe's NSBitmapImageRep's imageRepWithData:ocidOsDispatchData
#####################################
###quiet zone用に画像をパディングする
set numPadWidth to ((ocidCIImageWidth * numWidth) + (numWidth * 6)) as integer
set numPadHight to ((ocidCIImageHight * numHight) + (numHight * 6)) as integer
###左右に4セル分づつ余白 quiet zoneを足す
####まずは元のコードのサイズに8セルサイズ分足したサイズの画像を作って
set ocidNSBitmapImagePadRep to (objMe's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:numPadWidth pixelsHigh:numPadHight bitsPerSample:8 samplesPerPixel:4 hasAlpha:true isPlanar:false colorSpaceName:(objMe's NSCalibratedRGBColorSpace) bitmapFormat:(objMe's NSAlphaFirstBitmapFormat) bytesPerRow:0 bitsPerPixel:32)
###初期化
objMe's NSGraphicsContext's saveGraphicsState()
###ビットマップイメージ
(objMe's NSGraphicsContext's setCurrentContext:(objMe's NSGraphicsContext's graphicsContextWithBitmapImageRep:ocidNSBitmapImagePadRep))
###塗り色を『白』に指定して
objMe's NSColor's whiteColor()'s |set|()
###画像にする
objMe's NSRectFill({origin:{x:0, y:0}, |size|:{width:numPadWidth, height:numPadHight}})
###出来上がった画像にバーコードを左右3セル分ずらした位置にCompositeSourceOverする
ocidNSBitmapImageRep's drawInRect:{origin:{x:(numWidth * 3), y:(numHight * 3)}, |size|:{width:numPadWidth, Hight:numPadHight}} fromRect:{origin:{x:0, y:0}, |size|:{width:numPadWidth, height:numPadHight}} operation:(objMe's NSCompositeSourceOver) fraction:1.0 respectFlipped:true hints:(missing value)
####画像作成終了
objMe's NSGraphicsContext's restoreGraphicsState()

#####################################
####JPEG用の圧縮プロパティ
##set ocidNSSingleEntryDictionary to objMe's NSDictionary's dictionaryWithObject:1 forKey:(objMe's NSImageCompressionFactor)
####PNG用の圧縮プロパティ
set ocidNSSingleEntryDictionary to objMe's NSDictionary's dictionaryWithObject:true forKey:(objMe's NSImageInterlaced)

#####出力イメージへ変換
set ocidNSInlineData to (ocidNSBitmapImagePadRep's representationUsingType:(objMe's NSBitmapImageFileTypePNG) |properties|:ocidNSSingleEntryDictionary)
(*
NSBitmapImageFileTypeJPEG
NSBitmapImageFileTypePNG
NSBitmapImageFileTypeGIF
NSBitmapImageFileTypeBMP
NSBitmapImageFileTypeTIFF
NSBitmapImageFileTypeJPEG2000
*)
######インラインデータをファイルに書き出し
set boolMakeCode128 to (ocidNSInlineData's writeToFile:strSaveFilePath atomically:true)



set aliasDirPath to POSIX file strDirPath as alias

tell application "Finder"

select aliasDirPath
activate
end tell


return

#####################################
set targetURL to ("file://" & strSaveFilePath & "") as text
#####################################
repeat 1 times
####NSMutableDictionaryの初期化
set ocidNSDictionaryM to objMe's NSMutableDictionary's dictionary()
####ウィンドのサイズ
set {numWidth, numHeight} to {600, 300}
tell ocidNSDictionaryM
####画像のパス
its setObject:targetURL forKey:"theURL"
####ウィンドのサイズ
its setObject:numWidth forKey:"width"
its setObject:numHeight forKey:"height"
end tell
if objMe's NSThread's isMainThread() as boolean then
####Webビューを表示する
my performWebView:ocidNSDictionaryM
else
my performSelectorOnMainThread:"performWebView:" withObject:ocidNSDictionaryM waitUntilDone:true
end if
tell ocidNSDictionaryM
activate
end tell
#####10秒間開いたら閉じる
#####ここでこの処理をしたのはスクリプトメニューからの実行を配慮して
delay 10
end repeat



on performWebView:ocidNSDictionaryM
set {width, height} to {ocidNSDictionaryM's objectForKey:"width", ocidNSDictionaryM's objectForKey:"height"}
set strURL to (ocidNSDictionaryM's objectForKey:"theURL")
########
set theConfiguration to objMe's WKWebViewConfiguration's alloc()'s init()
set ocidURL to objNSURL's URLWithString:strURL
set theFetch to objNSString's stringWithContentsOfURL:ocidURL encoding:(objMe's NSUTF8StringEncoding) |error|:(missing value)
set theUserScript to objMe's WKUserScript's alloc()'s initWithSource:theFetch injectionTime:(objMe's WKUserScriptInjectionTimeAtDocumentEnd) forMainFrameOnly:true
set theUserContentController to objMe's WKUserContentController's alloc()'s init()
theUserContentController's addUserScript:theUserScript
theConfiguration's setUserContentController:theUserContentController
set webViewSize to objMe's NSMakeRect(0, 0, width, height)
set webView to objMe's WKWebView's alloc()'s initWithFrame:webViewSize configuration:theConfiguration
webView's setNavigationDelegate:me
webView's setUIDelegate:me
webView's setTranslatesAutoresizingMaskIntoConstraints:true
set theURL to objMe's |NSURL|'s URLWithString:strURL
set theRequest to objMe's NSURLRequest's requestWithURL:theURL
webView's loadRequest:theRequest
set ocidWebView to webView
########
set listWindowSize to objMe's NSMakeRect(0, 0, width, height)
set numStyleMaskNo to (objMe's NSWindowStyleMaskTitled as integer)
set numStyleMaskNo to numStyleMaskNo + (objMe's NSWindowStyleMaskClosable as integer)
set numStyleMaskNo to numStyleMaskNo + (objMe's NSWindowStyleMaskMiniaturizable as integer)
set numStyleMaskNo to numStyleMaskNo + (objMe's NSWindowStyleMaskResizable as integer)
set ocidWindow to objMe's NSWindow's alloc()'s initWithContentRect:listWindowSize styleMask:numStyleMaskNo backing:2 defer:yes
########
ocidWindow's setContentView:ocidWebView
set ocidNSWindowController to objMe's NSWindowController's alloc()'s initWithWindow:ocidWindow
ocidNSWindowController's showWindow:me
ocidNSWindowController's |window|'s |center|()
ocidNSWindowController's |window|'s makeKeyAndOrderFront:me
tell ocidNSDictionaryM to its setObject:ocidWindow forKey:"window"
end performWebView:

|

[WKWebView]QRコードを表示する

webViewの基本構造はこちらを使用しています。
https://macscripter.net/viewtopic.php?pid=209146



#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#webViewベーススクリプト
#https://macscripter.net/viewtopic.php?pid=209146
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use framework "WebKit"
use scripting additions

property objMe : a reference to current application
property objNSURL : a reference to objMe's NSURL
property objNSString : a reference to objMe's NSString
set objFileManager to objMe's NSFileManager's defaultManager()

#####################################
set aliasIconPath to POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/BookmarkIcon.icns" as alias
set theResponse to "" as text
try
set objResponse to (display dialog "バーコードの内容を入力" with title "QRコードを作成します" default answer theResponse buttons {"OK", "キャンセル"} default button "OK" cancel button "キャンセル" with icon aliasIconPath giving up after 20 without hidden answer)
on error
log "エラーしました"
return
end try
if true is equal to (gave up of objResponse) then
return "時間切れですやりなおしてください"
end if
if "OK" is equal to (button returned of objResponse) then
set strText to (text returned of objResponse) as text
else
return "キャンセル"
end if
###フォルダのパス
###ピクチャーフォルダのパス
set aliasDirPath to (path to pictures folder from user domain) as alias
set strDirPath to POSIX path of aliasDirPath as text
####フォルダ名
set strFolderName to "QRcode" as text
set strDirPath to ("" & strDirPath & strFolderName & "") as text
###NSStringテキスト
set ocidDirPath to objNSString's stringWithString:strDirPath
###フォルダを作る
###途中のフォルダも作る-->true
set boolMakeNewFolder to (objFileManager's createDirectoryAtPath:ocidDirPath withIntermediateDirectories:true attributes:(missing value) |error|:(missing value))

####日付フォーマット
set prefDateFormat to "yyyyMMddHHmmss"
set ocidFormatter to objMe's NSDateFormatter's alloc()'s init()
ocidFormatter's setLocale:(objMe's NSLocale's localeWithLocaleIdentifier:"ja_JP_POSIX")
ocidFormatter's setDateFormat:(prefDateFormat as string)
set strDateAndTime to (ocidFormatter's stringFromDate:(current date)) as text
#####日付をファイル名にする
set strSaveFilePath to strDirPath & "/" & strDateAndTime & ".png"

#####################################
set strInputText to (strText) as text
####テキストをNSString
set ocidInputString to objNSString's stringWithString:strInputText
#####################################
##全角を半角に変換して
set ocidInputStringHalfwidth to (ocidInputString's stringByApplyingTransform:(objMe's NSStringTransformFullwidthToHalfwidth) |reverse|:false)
##制御文字取り除き
set ocidwhitespaceAndNewlineCharacterSet to objMe's NSCharacterSet's whitespaceAndNewlineCharacterSet
set ocidInputString to ocidInputStringHalfwidth's stringByTrimmingCharactersInSet:ocidwhitespaceAndNewlineCharacterSet
##スペース取り除き
set ocidSearchString to objNSString's stringWithString:" "
set ocidReplacementString to objNSString's stringWithString:""
set ocidTrimmingText to ocidInputString's stringByReplacingOccurrencesOfString:ocidSearchString withString:ocidReplacementString
##ハイフン取り除き
set ocidSearchString to objNSString's stringWithString:"-"
set ocidTrimmingText to ocidTrimmingText's stringByReplacingOccurrencesOfString:ocidSearchString withString:ocidReplacementString
#####################################
####テキストをUTF8
set ocidUtf8InputString to ocidTrimmingText's dataUsingEncoding:(objMe's NSUTF8StringEncoding)
####CIQRCodeGenerator初期化
set ocidQRcodeImage to objMe's CIFilter's filterWithName:"CIQRCodeGenerator"
ocidQRcodeImage's setDefaults()
###テキスト設定
ocidQRcodeImage's setValue:ocidUtf8InputString forKey:"inputMessage"
###読み取り誤差値設定L, M, Q, H
ocidQRcodeImage's setValue:"Q" forKey:"inputCorrectionLevel"
###QRコード本体のイメージ
set ocidCIImage to ocidQRcodeImage's outputImage()
-->ここで生成されるのはQRのセルが1x1pxの最小サイズ
###QRコードの縦横取得
set ocidCIImageDimension to ocidCIImage's extent()
set ocidCIImageWidth to (item 1 of item 2 of ocidCIImageDimension) as integer
set ocidCIImageHight to (item 2 of item 2 of ocidCIImageDimension) as integer
###最終的に出力したいpxサイズ
set numScaleMax to 580
###整数で拡大しないとアレなのでの値のニアなサイズになります
set numWidth to ((numScaleMax / ocidCIImageWidth) div 1) as integer
set numHight to ((numScaleMax / ocidCIImageHight) div 1) as integer
###↑サイズの拡大縮小する場合はここで値を調整すれば良い
####変換スケール作成-->拡大
set recordScalse to objMe's CGAffineTransform's CGAffineTransformMakeScale(numWidth, numHight)
##変換スケールを適応(元のサイズに元のサイズのスケール適応しても意味ないけど
set ocidCIImageScaled to ocidCIImage's imageByApplyingTransform:recordScalse
#######元のセルが1x1pxの最小サイズで出したいときはここで処理
##set ocidCIImageScaled to ocidCIImage
###イメージデータを展開
set ocidNSCIImageRep to objMe's NSCIImageRep's imageRepWithCIImage:ocidCIImageScaled
###出力用のイメージの初期化
set ocidNSImageScaled to objMe's NSImage's alloc()'s initWithSize:(ocidNSCIImageRep's |size|())
###イメージデータを合成
ocidNSImageScaled's addRepresentation:ocidNSCIImageRep
###出来上がったデータはOS_dispatch_data
set ocidOsDispatchData to ocidNSImageScaled's TIFFRepresentation()
####NSBitmapImageRep
set ocidNSBitmapImageRep to objMe's NSBitmapImageRep's imageRepWithData:ocidOsDispatchData
#####################################
###quiet zone用に画像をパディングする
set numPadWidth to ((ocidCIImageWidth * numWidth) + (numWidth * 6)) as integer
set numPadHight to ((ocidCIImageHight * numHight) + (numHight * 6)) as integer
###左右に4セル分づつ余白 quiet zoneを足す
####まずは元のQRコードのサイズに8セルサイズ分足したサイズの画像を作って
set ocidNSBitmapImagePadRep to (objMe's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:numPadWidth pixelsHigh:numPadHight bitsPerSample:8 samplesPerPixel:4 hasAlpha:true isPlanar:false colorSpaceName:(objMe's NSCalibratedRGBColorSpace) bitmapFormat:(objMe's NSAlphaFirstBitmapFormat) bytesPerRow:0 bitsPerPixel:32)
###初期化
objMe's NSGraphicsContext's saveGraphicsState()
###ビットマップイメージ
(objMe's NSGraphicsContext's setCurrentContext:(objMe's NSGraphicsContext's graphicsContextWithBitmapImageRep:ocidNSBitmapImagePadRep))
###塗り色を『白』に指定して
objMe's NSColor's whiteColor()'s |set|()
###画像にする
objMe's NSRectFill({origin:{x:0, y:0}, |size|:{width:numPadWidth, height:numPadHight}})
###出来上がった画像にQRバーコードを左右3セル分ずらした位置にCompositeSourceOverする
ocidNSBitmapImageRep's drawInRect:{origin:{x:(numWidth * 3), y:(numHight * 3)}, |size|:{width:numPadWidth, Hight:numPadHight}} fromRect:{origin:{x:0, y:0}, |size|:{width:numPadWidth, height:numPadHight}} operation:(objMe's NSCompositeSourceOver) fraction:1.0 respectFlipped:true hints:(missing value)
####画像作成終了
objMe's NSGraphicsContext's restoreGraphicsState()

#####################################
####JPEG用の圧縮プロパティ
##set ocidNSSingleEntryDictionary to objMe's NSDictionary's dictionaryWithObject:1 forKey:(objMe's NSImageCompressionFactor)
####PNG用の圧縮プロパティ
set ocidNSSingleEntryDictionary to objMe's NSDictionary's dictionaryWithObject:true forKey:(objMe's NSImageInterlaced)

#####出力イメージへ変換
set ocidNSInlineData to (ocidNSBitmapImagePadRep's representationUsingType:(objMe's NSBitmapImageFileTypePNG) |properties|:ocidNSSingleEntryDictionary)
(*
NSBitmapImageFileTypeJPEG
NSBitmapImageFileTypePNG
NSBitmapImageFileTypeGIF
NSBitmapImageFileTypeBMP
NSBitmapImageFileTypeTIFF
NSBitmapImageFileTypeJPEG2000
*)
######インラインデータをファイルに書き出し
set boolMakeQrCode to (ocidNSInlineData's writeToFile:strSaveFilePath atomically:true)

set targetURL to ("file://" & strSaveFilePath & "") as text
#####################################
repeat 1 times
####NSMutableDictionaryの初期化
set ocidNSDictionaryM to objMe's NSMutableDictionary's dictionary()
####ウィンドのサイズ
set {numWidth, numHeight} to {600, 600}
tell ocidNSDictionaryM
####画像のパス
its setObject:targetURL forKey:"theURL"
####ウィンドのサイズ
its setObject:numWidth forKey:"width"
its setObject:numHeight forKey:"height"
end tell
if objMe's NSThread's isMainThread() as boolean then
####Webビューを表示する
my performWebView:ocidNSDictionaryM
else
my performSelectorOnMainThread:"performWebView:" withObject:ocidNSDictionaryM waitUntilDone:true
end if
tell ocidNSDictionaryM
activate
end tell
#####10秒間開いたら閉じる
#####ここでこの処理をしたのはスクリプトメニューからの実行を配慮して
delay 10
end repeat



on performWebView:ocidNSDictionaryM
set {width, height} to {ocidNSDictionaryM's objectForKey:"width", ocidNSDictionaryM's objectForKey:"height"}
set strURL to (ocidNSDictionaryM's objectForKey:"theURL")
########
set theConfiguration to objMe's WKWebViewConfiguration's alloc()'s init()
set ocidURL to objNSURL's URLWithString:strURL
set theFetch to objNSString's stringWithContentsOfURL:ocidURL encoding:(objMe's NSUTF8StringEncoding) |error|:(missing value)
set theUserScript to objMe's WKUserScript's alloc()'s initWithSource:theFetch injectionTime:(objMe's WKUserScriptInjectionTimeAtDocumentEnd) forMainFrameOnly:true
set theUserContentController to objMe's WKUserContentController's alloc()'s init()
theUserContentController's addUserScript:theUserScript
theConfiguration's setUserContentController:theUserContentController
set webViewSize to objMe's NSMakeRect(0, 0, width, height)
set webView to objMe's WKWebView's alloc()'s initWithFrame:webViewSize configuration:theConfiguration
webView's setNavigationDelegate:me
webView's setUIDelegate:me
webView's setTranslatesAutoresizingMaskIntoConstraints:true
set theURL to objMe's |NSURL|'s URLWithString:strURL
set theRequest to objMe's NSURLRequest's requestWithURL:theURL
webView's loadRequest:theRequest
set ocidWebView to webView
########
set listWindowSize to objMe's NSMakeRect(0, 0, width, height)
set numStyleMaskNo to (objMe's NSWindowStyleMaskTitled as integer)
set numStyleMaskNo to numStyleMaskNo + (objMe's NSWindowStyleMaskClosable as integer)
set numStyleMaskNo to numStyleMaskNo + (objMe's NSWindowStyleMaskMiniaturizable as integer)
set numStyleMaskNo to numStyleMaskNo + (objMe's NSWindowStyleMaskResizable as integer)
set ocidWindow to objMe's NSWindow's alloc()'s initWithContentRect:listWindowSize styleMask:numStyleMaskNo backing:2 defer:yes
########
ocidWindow's setContentView:ocidWebView
set ocidNSWindowController to objMe's NSWindowController's alloc()'s initWithWindow:ocidWindow
ocidNSWindowController's showWindow:me
ocidNSWindowController's |window|'s |center|()
ocidNSWindowController's |window|'s makeKeyAndOrderFront:me
tell ocidNSDictionaryM to its setObject:ocidWindow forKey:"window"
end performWebView:


|

[json]QRコードのイメージファイルをデコードする

api.qrserver.comのAPIを利用します

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

property objMe : a reference to current application
property objNSString : a reference to objMe's NSString
property objNSDictionary : a reference to objMe's NSDictionary
property objNSJSONSerialization : a reference to objMe's NSJSONSerialization

#####デフォルトロケーション
tell application "Finder"
##set aliasDefaultLocation to container of (path to me) as alias
set aliasDefaultLocation to (path to desktop folder from user domain) as alias
end tell

#####ファイル選択のダイアログ
set aliasFile to (choose file with prompt "QRコードのイメージファイルを選んでください" default location (aliasDefaultLocation) of type {"public.image"} with invisibles and showing package contents without multiple selections allowed) as alias
#####戻り値をパスに
set strFilePath to POSIX path of aliasFile as text
#####zxing.org使う場合
###set strCommandText to "/usr/bin/curl -d \"f=file\" --data-binary 'decode=@" & strFilePath & "' 'https://zxing.org/w/decode.jspx?'"
#####コマンドライン整形
set strCommandText to "/usr/bin/curl -X POST -H \"Content-Type: multipart/form-data\" -F \"file=@" & strFilePath & "\" \"http://api.qrserver.com/v1/read-qr-code/\" "
#####コマンド実行 戻り値はJSON
set jsonResponse to (do shell script strCommandText) as text
#####NSDictionary初期化
set ocidNSDictionaryM to objNSDictionary's dictionary()
#####↑このNSDictionaryJSONの値を格納
set ocidJsonResponse to (objNSJSONSerialization's JSONObjectWithData:((objNSString's stringWithString:jsonResponse)'s dataUsingEncoding:(objMe's NSUTF8StringEncoding)) options:0 |error|:(missing value))
#####値を取り出す
set recodeCenters to (ocidJsonResponse's symbol)'s valueForKey:"data"
#####ダイアログを出す
set aliasIconPath to POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/BookmarkIcon.icns" as alias
display dialog "QRバーコードの内容・デコード結果" with title "グローバル情報" default answer (recodeCenters as text) buttons {"OK", "キャンセル"} default button "OK" cancel button "キャンセル" with icon aliasIconPath giving up after 10 without hidden answer

log (recodeCenters as text)
return

|

[QRCode]Line Out呼び出し用のQRバーコード生成

Img_0130

リンク先がこの画面のQRバーコードを生成します

ダウンロード - lineoutqr.scpt.zip



#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
(*
ラインのURL仕様はこちら
https://developers.line.biz/ja/docs/messaging-api/using-line-url-scheme
*)
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use framework "CoreImage"
use scripting additions

property objMe : a reference to current application
property objNSString : a reference to objMe's NSString
set objFileManager to objMe's NSFileManager's defaultManager()

set strBaseUrlt to "https://line.me/R/call/81/" as text

set aliasIconPath to POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/BookmarkIcon.icns" as alias
set theResponse to "電話番号を入力" as text
try
set objResponse to (display dialog "電話番号を入力してください" with title "QRコードを作成します" default answer theResponse buttons {"OK", "キャンセル"} default button "OK" cancel button "キャンセル" with icon aliasIconPath giving up after 20 without hidden answer)
on error
log "エラーしました"
return
end try
if true is equal to (gave up of objResponse) then
return "時間切れですやりなおしてください"
end if
if "OK" is equal to (button returned of objResponse) then
set strText to (text returned of objResponse) as text
else
return "キャンセル"
end if


###フォルダのパス
###ピクチャーフォルダのパス
set aliasDirPath to (path to pictures folder from user domain) as alias
set strDirPath to POSIX path of aliasDirPath as text
####フォルダ名
set strFolderName to "QRcode" as text
set strDirPath to ("" & strDirPath & strFolderName & "") as text
###NSStringテキスト
set ocidDirPath to objNSString's stringWithString:strDirPath
###フォルダを作る
###途中のフォルダも作る-->true
set boolMakeNewFolder to (objFileManager's createDirectoryAtPath:ocidDirPath withIntermediateDirectories:true attributes:(missing value) |error|:(missing value))

####日付フォーマット
set prefDateFormat to "yyyyMMddHHmmss"
set ocidFormatter to objMe's NSDateFormatter's alloc()'s init()
ocidFormatter's setLocale:(objMe's NSLocale's localeWithLocaleIdentifier:"ja_JP_POSIX")
ocidFormatter's setDateFormat:(prefDateFormat as string)
set strDateAndTime to (ocidFormatter's stringFromDate:(current date)) as text
#####日付をファイル名にする
set strSaveFilePath to strDirPath & "/" & strDateAndTime & ".png"


################################################################
set strInputText to (strBaseUrlt & strText) as text
####テキストをNSString
set ocidInputString to objNSString's stringWithString:strInputText
################################################################
##全角を半角に変換して
set ocidInputStringHalfwidth to (ocidInputString's stringByApplyingTransform:(objMe's NSStringTransformFullwidthToHalfwidth) |reverse|:false)
##制御文字取り除き
set ocidwhitespaceAndNewlineCharacterSet to objMe's NSCharacterSet's whitespaceAndNewlineCharacterSet
set ocidInputString to ocidInputStringHalfwidth's stringByTrimmingCharactersInSet:ocidwhitespaceAndNewlineCharacterSet
##スペース取り除き
set ocidSearchString to objNSString's stringWithString:" "
set ocidReplacementString to objNSString's stringWithString:""
set ocidTrimmingText to ocidInputString's stringByReplacingOccurrencesOfString:ocidSearchString withString:ocidReplacementString
##ハイフン取り除き
set ocidSearchString to objNSString's stringWithString:"-"
set ocidTrimmingText to ocidTrimmingText's stringByReplacingOccurrencesOfString:ocidSearchString withString:ocidReplacementString
################################################################
####テキストをUTF8
set ocidUtf8InputString to ocidTrimmingText's dataUsingEncoding:(objMe's NSUTF8StringEncoding)
####CIQRCodeGenerator初期化
set ocidQRcodeImage to objMe's CIFilter's filterWithName:"CIQRCodeGenerator"
ocidQRcodeImage's setDefaults()
###テキスト設定
ocidQRcodeImage's setValue:ocidUtf8InputString forKey:"inputMessage"
###読み取り誤差値設定L, M, Q, H
ocidQRcodeImage's setValue:"Q" forKey:"inputCorrectionLevel"
###QRコード本体のイメージ
set ocidCIImage to ocidQRcodeImage's outputImage()
-->ここで生成されるのはQRのセルが1x1pxの最小サイズ
###QRコードの縦横取得
set ocidCIImageDimension to ocidCIImage's extent()
set ocidCIImageWidth to (item 1 of item 2 of ocidCIImageDimension) as integer
set ocidCIImageHight to (item 2 of item 2 of ocidCIImageDimension) as integer
###最終的に出力したいpxサイズ
set numScaleMax to 580
###整数で拡大しないとアレなのでの値のニアなサイズになります
set numWidth to ((numScaleMax / ocidCIImageWidth) div 1) as integer
set numHight to ((numScaleMax / ocidCIImageHight) div 1) as integer
###↑サイズの拡大縮小する場合はここで値を調整すれば良い
####変換スケール作成-->拡大
set recordScalse to objMe's CGAffineTransform's CGAffineTransformMakeScale(numWidth, numHight)
##変換スケールを適応(元のサイズに元のサイズのスケール適応しても意味ないけど
set ocidCIImageScaled to ocidCIImage's imageByApplyingTransform:recordScalse
#######元のセルが1x1pxの最小サイズで出したいときはここで処理
##set ocidCIImageScaled to ocidCIImage
###イメージデータを展開
set ocidNSCIImageRep to objMe's NSCIImageRep's imageRepWithCIImage:ocidCIImageScaled
###出力用のイメージの初期化
set ocidNSImageScaled to objMe's NSImage's alloc()'s initWithSize:(ocidNSCIImageRep's |size|())
###イメージデータを合成
ocidNSImageScaled's addRepresentation:ocidNSCIImageRep
###出来上がったデータはOS_dispatch_data
set ocidOsDispatchData to ocidNSImageScaled's TIFFRepresentation()
####NSBitmapImageRep
set ocidNSBitmapImageRep to objMe's NSBitmapImageRep's imageRepWithData:ocidOsDispatchData
#################################################################
###quiet zone用に画像をパディングする
set numPadWidth to ((ocidCIImageWidth * numWidth) + (numWidth * 6)) as integer
set numPadHight to ((ocidCIImageHight * numHight) + (numHight * 6)) as integer
###左右に4セル分づつ余白 quiet zoneを足す
####まずは元のQRコードのサイズに8セルサイズ分足したサイズの画像を作って
set ocidNSBitmapImagePadRep to (objMe's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:numPadWidth pixelsHigh:numPadHight bitsPerSample:8 samplesPerPixel:4 hasAlpha:true isPlanar:false colorSpaceName:(objMe's NSCalibratedRGBColorSpace) bitmapFormat:(objMe's NSAlphaFirstBitmapFormat) bytesPerRow:0 bitsPerPixel:32)
###初期化
objMe's NSGraphicsContext's saveGraphicsState()
###ビットマップイメージ
(objMe's NSGraphicsContext's setCurrentContext:(objMe's NSGraphicsContext's graphicsContextWithBitmapImageRep:ocidNSBitmapImagePadRep))
###塗り色を『白』に指定して
objMe's NSColor's whiteColor()'s |set|()
###画像にする
objMe's NSRectFill({origin:{x:0, y:0}, |size|:{width:numPadWidth, height:numPadHight}})
###出来上がった画像にQRバーコードを左右3セル分ずらした位置にCompositeSourceOverする
ocidNSBitmapImageRep's drawInRect:{origin:{x:(numWidth * 3), y:(numHight * 3)}, |size|:{width:numPadWidth, Hight:numPadHight}} fromRect:{origin:{x:0, y:0}, |size|:{width:numPadWidth, height:numPadHight}} operation:(objMe's NSCompositeSourceOver) fraction:1.0 respectFlipped:true hints:(missing value)
####画像作成終了
objMe's NSGraphicsContext's restoreGraphicsState()

#################################################################
####JPEG用の圧縮プロパティ
##set ocidNSSingleEntryDictionary to objMe's NSDictionary's dictionaryWithObject:1 forKey:(objMe's NSImageCompressionFactor)
####PNG用の圧縮プロパティ
set ocidNSSingleEntryDictionary to objMe's NSDictionary's dictionaryWithObject:true forKey:(objMe's NSImageInterlaced)

#####出力イメージへ変換
set ocidNSInlineData to (ocidNSBitmapImagePadRep's representationUsingType:(objMe's NSBitmapImageFileTypePNG) |properties|:ocidNSSingleEntryDictionary)
(*
NSBitmapImageFileTypeJPEG
NSBitmapImageFileTypePNG
NSBitmapImageFileTypeGIF
NSBitmapImageFileTypeBMP
NSBitmapImageFileTypeTIFF
NSBitmapImageFileTypeJPEG2000
*)
######インラインデータをファイルに書き出し
set boolMakeQrCode to (ocidNSInlineData's writeToFile:strSaveFilePath atomically:true)

###################
###ここから出来上がったファイルについて
set aliasDirPath to POSIX file strDirPath as alias
###
tell application "Finder"
select aliasDirPath
end tell
###
tell application "Preview"
launch
activate
tell window 1
open (POSIX file strSaveFilePath as alias)
end tell
end tell

return true

|

[Map]位置情報をQRコードにする

macOSのMapアプリはApplescript対応していないので、System Eventsを使うのですが

20220430020817_1280x627x144_0
20220430020817_1280x557x144_0
状態によって
メニュー名が変わります
これに、気がつかなかった…トホホ

ダウンロード - geo2qr4.applescript.zip



#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use framework "CoreImage"
use scripting additions

property objMe : a reference to current application
property objNSString : a reference to objMe's NSString
set objFileManager to objMe's NSFileManager's defaultManager()

set theURL to ""
set ocidNSInlineData to ""
set ocidNSBitmapImagePadRep to ""


###set strLogFile to "/tmp/Geo2Qr4.txt"

tell application "System Events"
launch
end tell
(*
tell application "System Events"
tell application process "Maps"
keystroke "C" using {command down}
end tell
end tell

tell application "System Events"
keystroke "c" using {command down}
end tell
*)
try
tell application "System Events"
tell process "Maps"
get every menu bar
tell menu bar 1
get every menu bar item
tell menu bar item "編集"
get every menu bar item
tell menu "編集"
get every menu item
tell menu item "リンクをコピー"
click
end tell
end tell
end tell
end tell
end tell
end tell
on error
tell application "System Events"
tell process "Maps"
get every menu bar
tell menu bar 1
get every menu bar item
tell menu bar item "編集"
get every menu bar item
tell menu "編集"
get every menu item
tell menu item "コピー"
click
end tell
end tell
end tell
end tell
end tell
end tell
end try

(*
tell application "System Events"
tell process "Maps"
tell menu bar 1
tell menu bar item "Edit"
tell menu "Edit"
click menu item "Copy Link"
end tell
end tell
end tell
end tell
end tell
*)


tell application "Finder"
set theURL to (the clipboard) as text
end tell
delay 0.5


try
set objAns to (display alert "どちら用のQRコードを作成しますか?" message "iOSAppleMapQRコードを作成する OR 一般的なQRコードを作成する" default button 1 buttons {"AppleMap", "GoogleMap", "汎用"})
on error
log "エラーしました"
return
end try


set objResponse to (button returned of objAns) as text

set theURL to theURL as text


###
###do shell script "echo \"" & theURL & "\" >> " & strLogFile & ""
####

#########################
####URLの整形
set AppleScript's text item delimiters to "ll="
set listUrl to every text item of theURL as list
set AppleScript's text item delimiters to ""

set strSubURL to text item 2 of listUrl as text

set AppleScript's text item delimiters to "&"
set listSubURL to every text item of strSubURL as list
set AppleScript's text item delimiters to ""

set strLL to text item 1 of listSubURL as text

set AppleScript's text item delimiters to ","
set listLL to every text item of strLL as list
set AppleScript's text item delimiters to ""

set theLatitude to (item 1 of listLL) as text
set theLongitude to (item 2 of listLL) as text


####################################################

set strFileName to ("" & theLatitude & "-" & theLongitude & ".png")
#####################################################
if objResponse is "AppleMap" then
set theChl to ("GEO:" & theLatitude & "," & theLongitude & "") as text
log theChl
else if objResponse is "GoogleMap" then

###GoogleMap用の小数点以下の桁揃え
###逆ゼロサプレス
(**)
set AppleScript's text item delimiters to "."
set listLatitude to every text item of theLatitude as list
set AppleScript's text item delimiters to ""
set strLatitudeInt to text item 1 of listLatitude as text
set strLatitudeDecimal to text item 2 of listLatitude as text
set strLatitudeDecimal to (text 1 through 7 of (strLatitudeDecimal & "000000000")) as text
set theLatitude to ("" & strLatitudeInt & "." & strLatitudeDecimal & "")

set AppleScript's text item delimiters to "."
set listLongitude to every text item of theLongitude as list
set AppleScript's text item delimiters to ""
set strLongitudeInt to text item 1 of listLongitude as text
set strLongitudeDecimal to text item 2 of listLongitude as text
set strLongitudeDecimal to (text 1 through 7 of (strLongitudeDecimal & "000000000")) as text
set theLongitude to ("" & strLongitudeInt & "." & strLongitudeDecimal & "")

set theGooglemapParts to ("@" & theLatitude & "," & theLongitude & ",16z")

set theChl to ("https://www.google.com/maps/" & theGooglemapParts & "") as text
else
set theChl to ("http://maps.apple.com/?q=" & theLatitude & "," & theLongitude & "") as text
end if
#######################


###フォルダのパス
###ピクチャーフォルダのパス
tell application "Finder"
set aliasDirPath to (path to pictures folder from user domain) as alias
set strDirPath to POSIX path of aliasDirPath as text
end tell
####フォルダ名
set strFolderName to "QRcode" as text
set strDirPath to ("" & strDirPath & strFolderName & "") as text
###NSStringテキスト
set ocidDirPath to objNSString's stringWithString:strDirPath
###フォルダを作る
###途中のフォルダも作る-->true
set boolMakeNewFolder to (objFileManager's createDirectoryAtPath:ocidDirPath withIntermediateDirectories:true attributes:(missing value) |error|:(missing value))

####ファイルパス
set strSaveFilePath to ("" & strDirPath & "/" & strFileName & "") as text


################################################################
set strInputText to theChl as text
####テキストをNSString
set ocidInputString to objNSString's stringWithString:strInputText
####テキストをUTF8
set ocidUtf8InputString to ocidInputString's dataUsingEncoding:(objMe's NSUTF8StringEncoding)
####CIQRCodeGenerator初期化
set ocidQRcodeImage to objMe's CIFilter's filterWithName:"CIQRCodeGenerator"
ocidQRcodeImage's setDefaults()
###テキスト設定
ocidQRcodeImage's setValue:ocidUtf8InputString forKey:"inputMessage"
###読み取り誤差値設定L, M, Q, H
ocidQRcodeImage's setValue:"Q" forKey:"inputCorrectionLevel"
###QRコード本体のイメージ
set ocidCIImage to ocidQRcodeImage's outputImage()
-->ここで生成されるのはQRのセルが1x1pxの最小サイズ
###QRコードの縦横取得
set ocidCIImageDimension to ocidCIImage's extent()
set ocidCIImageWidth to (item 1 of item 2 of ocidCIImageDimension) as integer
set ocidCIImageHight to (item 2 of item 2 of ocidCIImageDimension) as integer
###最終的に出力したいpxサイズ
set numScaleMax to 720
###整数で拡大しないとアレなのでの値のニアなサイズになります
set numWidth to ((numScaleMax / ocidCIImageWidth) div 1) as integer
set numHight to ((numScaleMax / ocidCIImageHight) div 1) as integer
###↑サイズの拡大縮小する場合はここで値を調整すれば良い
####変換スケール作成-->拡大
set recordScalse to objMe's CGAffineTransform's CGAffineTransformMakeScale(numWidth, numHight)
##変換スケールを適応(元のサイズに元のサイズのスケール適応しても意味ないけど
set ocidCIImageScaled to ocidCIImage's imageByApplyingTransform:recordScalse
#######元のセルが1x1pxの最小サイズで出したいときはここで処理
##set ocidCIImageScaled to ocidCIImage
###イメージデータを展開
set ocidNSCIImageRep to objMe's NSCIImageRep's imageRepWithCIImage:ocidCIImageScaled
###出力用のイメージの初期化
set ocidNSImageScaled to objMe's NSImage's alloc()'s initWithSize:(ocidNSCIImageRep's |size|())
###イメージデータを合成
ocidNSImageScaled's addRepresentation:ocidNSCIImageRep
###出来上がったデータはOS_dispatch_data
set ocidOsDispatchData to ocidNSImageScaled's TIFFRepresentation()
####NSBitmapImageRep
set ocidNSBitmapImageRep to objMe's NSBitmapImageRep's imageRepWithData:ocidOsDispatchData
#################################################################
###quiet zone用に画像をパディングする
set numPadWidth to ((ocidCIImageWidth * numWidth) + (numWidth * 6)) as integer
set numPadHight to ((ocidCIImageHight * numHight) + (numHight * 6)) as integer
###左右に3セル分づつ余白 quiet zoneを足す
####まずは元のQRコードのサイズに6セルサイズ分足したサイズの画像を作って
set ocidNSBitmapImagePadRep to (objMe's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:numPadWidth pixelsHigh:numPadHight bitsPerSample:8 samplesPerPixel:4 hasAlpha:true isPlanar:false colorSpaceName:(objMe's NSCalibratedRGBColorSpace) bitmapFormat:(objMe's NSAlphaFirstBitmapFormat) bytesPerRow:0 bitsPerPixel:32)
###初期化
objMe's NSGraphicsContext's saveGraphicsState()
###ビットマップイメージ
(objMe's NSGraphicsContext's setCurrentContext:(objMe's NSGraphicsContext's graphicsContextWithBitmapImageRep:ocidNSBitmapImagePadRep))
###塗り色を『白』に指定して
objMe's NSColor's whiteColor()'s |set|()
##画像にする
objMe's NSRectFill({origin:{x:0, y:0}, |size|:{width:numPadWidth, height:numPadHight}})
###出来上がった画像にQRバーコードを左右3セル分ずらした位置にCompositeSourceOverする
ocidNSBitmapImageRep's drawInRect:{origin:{x:(numWidth * 3), y:(numHight * 3)}, |size|:{width:numPadWidth, Hight:numPadHight}} fromRect:{origin:{x:0, y:0}, |size|:{width:numPadWidth, height:numPadHight}} operation:(objMe's NSCompositeSourceOver) fraction:1.0 respectFlipped:true hints:(missing value)
####画像作成終了
objMe's NSGraphicsContext's restoreGraphicsState()

#################################################################

####JPEG用の圧縮プロパティ
##set ocidNSSingleEntryDictionary to objMe's NSDictionary's dictionaryWithObject:1 forKey:(objMe's NSImageCompressionFactor)
####PNG用の圧縮プロパティ
set ocidNSSingleEntryDictionary to objMe's NSDictionary's dictionaryWithObject:true forKey:(objMe's NSImageInterlaced)

#####出力イメージへ変換
set ocidNSInlineData to (ocidNSBitmapImagePadRep's representationUsingType:(objMe's NSBitmapImageFileTypePNG) |properties|:ocidNSSingleEntryDictionary)

######インラインデータをファイルに書き出し
set boolMakeQrCode to (ocidNSInlineData's writeToFile:strSaveFilePath atomically:true)

set aliasDirPath to POSIX file strDirPath as alias
###保存場所を開いて
tell application "Finder"
select aliasDirPath
end tell
####プレビューに表示
tell application "Preview"
launch
activate
open aliasDirPath
end tell


set theURL to ""
set the clipboard to theURL
set ocidNSInlineData to ""
set ocidNSBitmapImagePadRep to ""
return true


to doReplace(theText, orgStr, newStr)
set oldDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to orgStr
set tmpList to every text item of theText
set AppleScript's text item delimiters to newStr
set tmpStr to tmpList as text
set AppleScript's text item delimiters to oldDelim
return tmpStr
end doReplace

|

[Chrome]地図用のQRコードを生成する

AppleのURLに誤りがあったので修正
https://developer.apple.com/library/archive/featuredarticles/iPhoneURLScheme_Reference/MapLinks/MapLinks.html


(*


Chromeで開いているページのQRを作成します。
たぶんiOS専用 

20190706 初回作成
20210429 URLを修正

APIの仕様は
https://developers.google.com/chart/infographics/docs/qr_codes


*)

tell application "Google Chrome"
activate
tell window 1
tell active tab
set theURL to URL as text
end tell
end tell
end tell

tell application "Finder"
activate
set objAns to ¬
display alert ¬
"どちら用のQRコードを作成しますか?" message ¬
"iOSAppleMapQRコードを作成する OR 一般的なQRコードを作成する" default button 1 ¬
buttons {"AppleMap", "GoogleMap", "汎用"}
end tell


set AppleScript's text item delimiters to {"/"}
set listUrl to every text item of theURL as list
set numCntUrl to (count of listUrl) as number
set numSepUrl to 1 as number
set AppleScript's text item delimiters to {""}
log numCntUrl

repeat numCntUrl times
set theSepUrl to (item numSepUrl of listUrl) as text
try
set theUrlParts to (the character 1 of theSepUrl)
on error
set theUrlParts to " "
end try


if theUrlParts is "@" then
set theGooglemapParts to theSepUrl
set theSepUrl to doReplace(theSepUrl, "@", "")
set AppleScript's text item delimiters to {","}
set listSepUrl to every text item of theSepUrl as list

set theLatitude to (item 1 of listSepUrl) as text
set theLongitude to (item 2 of listSepUrl) as text

set AppleScript's text item delimiters to {""}
end if
set numSepUrl to numSepUrl + 1 as number
end repeat





if (button returned of objAns) is "AppleMap" then

set theChl to ("GEO:" & theLatitude & "," & theLongitude & "") as text
log theChl
else if (button returned of objAns) is "GoogleMap" then
set theChl to ("https://www.google.com/maps/" & theGooglemapParts & "") as text
else
set theChl to ("http://maps.apple.com/?ll=" & theLatitude & "," & theLongitude & "") as text

end if


--API各項目
--BASE URL
set theApiUrl to "https://chart.googleapis.com/chart?" as text

set theCht to "qr" as text

set theChs to "540x540" as text

set theChoe to "UTF-8" as text

---L M Q R
set theChld to "Q" as text

--URLを整形
set theOpenUrl to ("" & theApiUrl & "&cht=" & theCht & "&chs=" & theChs & "&choe=" & theChoe & "&chld=" & theChld & "&chl=" & theChl & "") as text


-----Chromeで開く
tell application "Google Chrome"
activate
tell window 1
set active tab index to 1
make new tab
tell active tab
set URL to theOpenUrl
end tell
end tell
end tell







to doReplace(theText, orgStr, newStr)
set oldDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to orgStr
set tmpList to every text item of theText
set AppleScript's text item delimiters to newStr
set tmpStr to tmpList as text
set AppleScript's text item delimiters to oldDelim
return tmpStr
end doReplace

|

[AppleScript]セルサイズが1pxのQRコードを作る

QRバーコードを作ります
セルサイズ『黒い塗りの1単位』が1pxのバーコードを作成します
--->この1pxバーコードを整数倍する事で『アンチエイリアス』の無い規格通りのバーコードができます。
PhotoShop等で拡大する場合は『ニアレストネイバー』で拡大すれば、アンチエイリアス立ちません。
最近の高画質環境では小さな事になりましたが
やっぱり、プロなんだし。ねっ
と、偉そうに…いったものの
最初から1pxなんだよね…出来上がりが。

ダウンロード - qrsell1px.scpt.zip



#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use framework "CoreImage"
use scripting additions

property objMe : a reference to current application
property objNSString : a reference to objMe's NSString
set objFileManager to objMe's NSFileManager's defaultManager()

set strText to "https://apps.apple.com/jp/developer/adobe-inc/id331646274?see-all=i-phonei-pad-apps"


###フォルダのパス
###ピクチャーフォルダのパス
set aliasDirPath to (path to pictures folder from user domain) as alias
set strDirPath to POSIX path of aliasDirPath as text
####フォルダ名
set strFolderName to "QRcode" as text
set strDirPath to ("" & strDirPath & strFolderName & "") as text
###NSStringテキスト
set ocidDirPath to objNSString's stringWithString:strDirPath
###フォルダを作る
###途中のフォルダも作る-->true
set boolMakeNewFolder to (objFileManager's createDirectoryAtPath:ocidDirPath withIntermediateDirectories:true attributes:(missing value) |error|:(missing value))

####日付フォーマット
set prefDateFormat to "yyyyMMddHHmmss"
set ocidFormatter to objMe's NSDateFormatter's alloc()'s init()
ocidFormatter's setLocale:(objMe's NSLocale's localeWithLocaleIdentifier:"ja_JP_POSIX")
ocidFormatter's setDateFormat:(prefDateFormat as string)
set strDateAndTime to (ocidFormatter's stringFromDate:(current date)) as text
#####日付をファイル名にする
set strSaveFilePath to strDirPath & "/" & strDateAndTime & ".png"

########################################################
set strInputText to strText as text
####テキストをNSString
set ocidInputString to objNSString's stringWithString:strInputText
####テキストをUTF8
set ocidUtf8InputString to ocidInputString's dataUsingEncoding:(objMe's NSUTF8StringEncoding)
####CIQRCodeGenerator初期化
set ocidQRcodeImage to objMe's CIFilter's filterWithName:"CIQRCodeGenerator"
ocidQRcodeImage's setDefaults()
###テキスト設定
ocidQRcodeImage's setValue:ocidUtf8InputString forKey:"inputMessage"
###読み取り誤差値設定L, M, Q, H
ocidQRcodeImage's setValue:"Q" forKey:"inputCorrectionLevel"
###QRコード本体のイメージ
set ocidCIImage to ocidQRcodeImage's outputImage()
-->ここで生成されるのはQRのセルが1x1pxの最小サイズ
###QRコードの縦横取得
set ocidCIImageDimension to ocidCIImage's extent()
set ocidCIImageWidth to (item 1 of item 2 of ocidCIImageDimension) as integer
set ocidCIImageHight to (item 2 of item 2 of ocidCIImageDimension) as integer
###最終的に出力したいpxサイズ
set numScaleMax to 580
###整数で拡大しないとアレなのでの値のニアなサイズになります
set numWidth to ((numScaleMax / ocidCIImageWidth) div 1) as integer
set numHight to ((numScaleMax / ocidCIImageHight) div 1) as integer
####
set ocidCIImageScaled to ocidCIImage
###イメージデータを展開
set ocidNSCIImageRep to objMe's NSCIImageRep's imageRepWithCIImage:ocidCIImageScaled
###出力用のイメージの初期化
set ocidNSImageScaled to objMe's NSImage's alloc()'s initWithSize:(ocidNSCIImageRep's |size|())
###イメージデータを合成
ocidNSImageScaled's addRepresentation:ocidNSCIImageRep
###出来上がったデータはOS_dispatch_data
set ocidOsDispatchData to ocidNSImageScaled's TIFFRepresentation()
####NSBitmapImageRep
set ocidNSBitmapImageRep to objMe's NSBitmapImageRep's imageRepWithData:ocidOsDispatchData
###################################################
###パディング3ピクセル
set numPadWidth to ((ocidCIImageWidth) + 6) as integer
set numPadHight to ((ocidCIImageHight) + 6) as integer
###左右に3pxづつ余白 quiet zoneを足す
####まずは元のQRコードのサイズに6px足したサイズの画像を作って
set ocidNSBitmapImagePadRep to (objMe's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:numPadWidth pixelsHigh:numPadHight bitsPerSample:8 samplesPerPixel:4 hasAlpha:true isPlanar:false colorSpaceName:(objMe's NSCalibratedRGBColorSpace) bitmapFormat:(objMe's NSAlphaFirstBitmapFormat) bytesPerRow:0 bitsPerPixel:32)
###初期化
objMe's NSGraphicsContext's saveGraphicsState()
###ビットマップイメージ
(objMe's NSGraphicsContext's setCurrentContext:(objMe's NSGraphicsContext's graphicsContextWithBitmapImageRep:ocidNSBitmapImagePadRep))
###塗り色を『白』に指定して
objMe's NSColor's whiteColor()'s |set|()
##画像にする
objMe's NSRectFill({origin:{x:0, y:0}, |size|:{width:numPadWidth, height:numPadHight}})
###出来上がった画像にQRバーコードを左右3pxずらした位置にCompositeSourceOverする
ocidNSBitmapImageRep's drawInRect:{origin:{x:3, y:3}, |size|:{width:numPadWidth, Hight:numPadHight}} fromRect:{origin:{x:0, y:0}, |size|:{width:numPadWidth, height:numPadHight}} operation:(objMe's NSCompositeSourceOver) fraction:1.0 respectFlipped:true hints:(missing value)
####画像作成終了
objMe's NSGraphicsContext's restoreGraphicsState()
###################################################
####PNG用の圧縮プロパティ
set ocidNSSingleEntryDictionary to objMe's NSDictionary's dictionaryWithObject:true forKey:(objMe's NSImageInterlaced)
####
set ocidNSInlineData to (ocidNSBitmapImagePadRep's representationUsingType:(objMe's NSBitmapImageFileTypePNG) |properties|:ocidNSSingleEntryDictionary)
#####出力イメージへ変換
#####set ocidNSInlineData to (ocidNSBitmapImagePadRep's representationUsingType:(objMe's NSBitmapImageFileTypePNG) |properties|:ocidNSSingleEntryDictionary)
(*
NSBitmapImageFileTypeJPEG
NSBitmapImageFileTypePNG
NSBitmapImageFileTypeGIF
NSBitmapImageFileTypeBMP
NSBitmapImageFileTypeTIFF
NSBitmapImageFileTypeJPEG2000
*)
######インラインデータをファイルに書き出し
set boolMakeQrCode to (ocidNSInlineData's writeToFile:strSaveFilePath atomically:true)


set aliasDirPath to POSIX file strDirPath as alias

tell application "Finder"

select aliasDirPath
activate
end tell

boolMakeQrCode

|

[AppleScript]カレンダーで選択中のイベントのQRコードを生成 改良版

[AppleScript]カレンダーで選択中のイベントのQRコードを生成
https://quicktimer.cocolog-nifty.com/icefloe/2022/01/post-583330.html
こちらの改良版
改良点
FaceTImeミーティングへの対応
通知設定1時間前をデフォルトに
値が無いイベントの場合に配慮 他

(************************************************************************

この上の▶︎をぽっちっとしてください
SelectedEventの値が更新されるタイミングに依存があります
イベントを選択してから、数秒待つのが吉です

通知は1時間前に指定してあります


OS12専用です

20220121 初回作成


************************************************************************)

tell application "Calendar"
activate
delay 3
end tell



set theSelectedList to (do shell script "defaults read com.apple.ical \"last selected calendar list item\"")

set theSelectedEvents to (do shell script "defaults read com.apple.ical SelectedEvents")
set theSelectedEvents to doReplace(theSelectedEvents, " ", "")
set theSelectedEvents to doReplace(theSelectedEvents, "{", "")
set theSelectedEvents to doReplace(theSelectedEvents, "}", "")
set theSelectedEvents to doReplace(theSelectedEvents, "iCal=(", "")
set theSelectedEvents to doReplace(theSelectedEvents, ");", "")
set theSelectedEvents to doReplace(theSelectedEvents, "\r", "")
set theSelectedEvents to doReplace(theSelectedEvents, "\"", "")

set aliasCoreTypes to POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources"
set aliasActionsIconPath to path to resource "Actions.icns" in bundle alias aliasCoreTypes

if theSelectedEvents = "" then
activate
display dialog ¬
(localized string "カレンダーのイベントを選択してから実行してください") with title ¬
"エラーが発生しました" with icon aliasActionsIconPath ¬
giving up after 10 ¬

return
end if

tell application "Calendar"
activate
tell calendar id (theSelectedList)

get name
get color
get writable
get description

tell event id (theSelectedEvents)
show
get recurrence
get stamp date
get excluded dates
get status
get uid

set theDTSTART to ""
set theDTSTART to (get start date)

set theDTEND to ""
set theDTEND to (get end date)



set theAllDay to (get allday event)
if theAllDay is "missing value" then
set theAllDay to false as boolean
end if

set theSummary to (get summary) as text
if theSummary is "missing value" then
set theSummary to theDTSTART as text
end if

set theDescription to (get description) as text
if theDescription is "missing value" then
set theDescription to "" as text
end if

set theSequence to (get sequence)
if theSequence is "missing value" then
set theSequence to "1" as text
end if

set theLocation to (get location) as text
if theLocation is "missing value" then
set theLocation to "" as text
end if


set theURL to (get url)
if theURL is "missing value" then
set theURL to "https://www.icloud.com/calendar/" as text
end if


end tell
end tell
end tell

if theAllDay is false then
set theDTSTART to ("DTSTART:" & getEventDateTime(theDTSTART))
set theDTEND to ("DTEND:" & getEventDateTime(theDTEND))
else
set theDTSTART to ("DTSTART;VALUE=DATE:" & getEventDate(theDTSTART))
set theDTEND to ("DTEND;VALUE=DATE:" & getEventDate(theDTEND))
end if

set theSequence to ("SEQUENCE:" & theSequence) as text

set theLocation to my encodeURL(theLocation)
set theLocation to ("LOCATION:" & theLocation) as text

set theSummary to my encodeURL(theSummary)
set theSummary to ("SUMMARY:" & theSummary) as text

if theDescription contains "FaceTime" then
set theDescription to doReplace(theDescription, "\r\n", "")
log theDescription
set AppleScript's text item delimiters to "\n"
set listDescription to every text item of theDescription as list
set AppleScript's text item delimiters to ""
set theURL to item 3 of listDescription as text
set theURL to doReplace(theURL, " ", "")
set theDescription to ("DESCRIPTION:Facetimeミーティング") as text
else
set theDescription to my encodeURL(theDescription)
set theDescription to ("DESCRIPTION:" & theDescription) as text
end if

set theURL to my encodeURL(theURL)
set theURL to ("URL;VALUE=URI:" & theURL) as text
log theURL

set theALARM to "BEGIN:VALARM%0ATRIGGER:-PT1H%0AATTACH;VALUE=URI:Chord%0AACTION:AUDIO%0AEND:VALARM"

---イベントの中を整形
set theChl to "BEGIN:VEVENT%0A" & "%0A" & theSummary & "%0A" & theLocation & "%0A" & theSequence & "%0A" & theDTSTART & "%0A" & theURL & "%0A" & theDescription & "%0A" & theDTEND & "%0A" & theALARM & "%0AEND:VEVENT" as text


---QRコードを生成
--BASE URL
set theApiUrl to "https://chart.googleapis.com/chart?" as text

set theCht to "qr" as text

set theChs to "540x540" as text

set theChoe to "UTF-8" as text

---L M Q R
set theChld to "L" as text

--URLを整形
set theOpenUrl to ("" & theApiUrl & "&cht=" & theCht & "&chs=" & theChs & "&choe=" & theChoe & "&chld=" & theChld & "&chl=" & theChl & "") as text


-----サファリで開く
tell application "Safari"
activate
make new document with properties {name:"QR-CODE by Google API"}
tell window 1
open location theOpenUrl
end tell
end tell




---URLエンコードのサブルーチン
to encodeURL(str)
set scpt to ("python3 -c 'import urllib.parse;[print(urllib.parse.quote(\"" & str & "\", safe=\"/:;!?=\"))]'") as text
return do shell script scpt
end encodeURL

to doReplace(theText, orgStr, newStr)
set oldDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to orgStr
set tmpList to every text item of theText
set AppleScript's text item delimiters to newStr
set tmpStr to tmpList as text
set AppleScript's text item delimiters to oldDelim
return tmpStr
end doReplace

to getEventDate(str)
set theYear to year of (str) as number
set theMonth to month of (str) as number
if theMonth < 10 then
set theMonth to ("0" & theMonth) as text
else
set theMonth to theMonth as text
end if
set theDate to day of (str) as number
if theDate < 10 then
set theDate to ("0" & theDate) as text
else
set theDate to theDate as text
end if

return (theYear & theMonth & theDate) as text
end getEventDate

to getEventDateTime(str)
set theYear to year of (str) as number
set theMonth to month of (str) as number
if theMonth < 10 then
set theMonth to ("0" & theMonth) as text
else
set theMonth to theMonth as text
end if
set theDate to day of (str) as number
if theDate < 10 then
set theDate to ("0" & theDate) as text
else
set theDate to theDate as text
end if
set theTime to time of (str)
set theHours to theTime div hours
if theHours < 10 then
set theHours to ("0" & theHours) as text
else
set theHours to theHours as text
end if
set theMinutes to (theTime - (theHours) * hours) div minutes
if theMinutes < 10 then
set theMinutes to ("0" & theMinutes) as text
else
set theMinutes to theMinutes as text
end if
set theSeconds to theTime mod minutes
if theSeconds < 10 then
set theSeconds to ("0" & theSeconds) as text
else
set theSeconds to theSeconds as text
end if

return (theYear & theMonth & theDate & "T" & theHours & theMinutes & theSeconds) as text
end getEventDateTime

|

[AppleScript]カレンダーで選択中のイベントのQRコードを生成

カレンダーで選択中のイベントのQRコードを生成します

ダウンロード - event2qr.scpt.zip

スクリプトメニューに入れて使ってください

Screencapture_960x458_20220122111946

iPhoneでイベント登録できます
Img_0068_20220122112001


(************************************************************************

この上の▶︎をぽっちっとしてください


選択中のカレンダーイベントからQRコードを作成します
かなりトリッキーな方法を利用していますので
sqlite を使って ZSERVERFILENAME を取得する方法
ZSERVERFILENAMEはローカルディスクにも存在するイベントのicsファイルの実態なので
そこから各種値を取得する方法です。

OS12専用です

20220121 初回作成


************************************************************************)

--- カレンダーが起動中か?確認 起動していない場合は終了
set aliasCoreTypes to POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources"
set aliasActionsIconPath to path to resource "Actions.icns" in bundle alias aliasCoreTypes
on objAppRun(appName)
tell application "System Events" to (name of processes) contains appName
end objAppRun
set boolAppRun to objAppRun("Calendar")
if boolAppRun then
else
activate
display dialog ¬
(localized string "カレンダーのイベントを選択してから実行してください") with title ¬
"エラーが発生しました" with icon aliasActionsIconPath ¬
giving up after 10 ¬

return
end if


---検索用 実際は使わない
set theSelectedList to (do shell script "defaults read com.apple.ical \"last selected calendar list item\"")

---選択中のイベントのIDを取得する
set theSelectedEvents to (do shell script "defaults read com.apple.ical SelectedEvents")
set theSelectedEvents to doReplace(theSelectedEvents, " ", "")
set theSelectedEvents to doReplace(theSelectedEvents, "{", "")
set theSelectedEvents to doReplace(theSelectedEvents, "}", "")
set theSelectedEvents to doReplace(theSelectedEvents, "iCal=(", "")
set theSelectedEvents to doReplace(theSelectedEvents, ");", "")
set theSelectedEvents to doReplace(theSelectedEvents, "\r", "")
set theSelectedEvents to doReplace(theSelectedEvents, "\"", "")
---SelectedEventsの戻り値が空の場合は終了
if theSelectedEvents = "" then
activate
display dialog ¬
(localized string "カレンダーのイベントを選択してから実行してください") with title ¬
"エラーが発生しました" with icon aliasActionsIconPath ¬
giving up after 10 ¬

return
end if
---Googleカレンダー対策
if theSelectedEvents contains "/" then
set AppleScript's text item delimiters to "/"
set listSelectedEvents to every text item of theSelectedEvents as list
set AppleScript's text item delimiters to ""
set theSelectedEvents to item 2 of listSelectedEvents
end if
----SQLからファイル名を取得する
set objSQL to (do shell script "sqlite3 ~/Library/Calendars/Calendar\\ Cache \"select * from ZCALENDARITEM;\" | grep \"" & theSelectedEvents & "\"")

set AppleScript's text item delimiters to "|"
set listEvent to every text item of objSQL as list
set AppleScript's text item delimiters to ""
set numList to count of listEvent
set theFileName to item 82 of listEvent
---Googleカレンダー対策
set theFileName to doReplace(theFileName, "%40", "@")
set theFileName to doReplace(theFileName, "google.com", "googlecom")
---カレンダーのディレクトリからファイルを探す
set theFilePath to (do shell script " find ~/Library/Calendars -type f -name \"*" & theFileName & "\" -print")
---ファイルの内容を読み込み
set theChl to (do shell script "cat '" & theFilePath & "'") as text
set AppleScript's text item delimiters to "\r"
set listData to (every text item of theChl) as list
set AppleScript's text item delimiters to ""
set numCntList to (count of listData) as number
---各種値を初期化
set numReadList to 1 as number
set theSequence to "0" as text
set theLocation to " " as text
set theDescription to " " as text
set theURL to "" as text
set theSummary to " " as text
set theDTSTART to "" as text
set theDTEND to "" as text

repeat numCntList times
set theLineData to (item numReadList of listData) as text
----EVENT ITEMを取得
if theLineData contains "SEQUENCE:" then
set theSequence to theLineData
set theSequence to doReplace(theLocation, "SEQUENCE:", "")
end if

if theLineData contains "LOCATION:" then
set theLocation to theLineData
set theLocation to doReplace(theLocation, "LOCATION:", "")
set theLocation to my encodeURL(theLocation)
end if
if theLineData contains "DESCRIPTION:" then
set theDescription to theLineData
set theDescription to doReplace(theDescription, "DESCRIPTION:", "")
set theDescription to my encodeURL(theDescription)

end if
if theLineData contains "SUMMARY:" then
set theSummary to theLineData
set theSummary to doReplace(theSummary, "SUMMARY:", "")
set theSummary to my encodeURL(theSummary)
end if
if theLineData contains "URL:" then
set theURL to theLineData
set theURL to doReplace(theURL, "URL:", "")
set theURL to my encodeURL(theURL)
else if theLineData contains "URL;" then
set theURL to theLineData
set theURL to doReplace(theURL, "VALUE=URI:", "")
set theURL to doReplace(theURL, "URL;", "")
set theURL to my encodeURL(theURL)
end if
if theLineData contains "DTSTART:" then
set theDTSTART to theLineData
set theDTSTART to doReplace(theDTSTART, "DTSTART:", "")
set theDTSTART to "DTSTART:" & theDTSTART
else if theLineData contains "DTSTART;VALUE=DATE:" then
set theDTSTART to theLineData
set theDTSTART to doReplace(theDTSTART, "DTSTART;VALUE=DATE:", "")
set theDTSTART to "DTSTART;VALUE=DATE:" & theDTSTART
else if theLineData contains "DTSTART;" then
set theDTSTART to theLineData
set theDTSTART to doReplace(theDTSTART, "DTSTART;TZID=Asia/Tokyo:", "")
set theDTSTART to "DTSTART:" & theDTSTART
end if
if theLineData contains "DTEND:" then
set theDTEND to theLineData
set theDTEND to doReplace(theDTEND, "DTEND:", "")
set theDTEND to "DTEND:" & theDTEND
else if theLineData contains "DTEND;VALUE=DATE:" then
set theDTEND to theLineData
set theDTEND to doReplace(theDTEND, "DTEND;VALUE=DATE:", "")
set theDTEND to "DTEND;VALUE=DATE:" & theDTEND
else if theLineData contains "DTEND;" then
set theDTEND to theLineData
set theDTEND to doReplace(theDTEND, "DTEND;TZID=Asia/Tokyo:", "")
set theDTEND to "DTEND:" & theDTEND
end if

set numReadList to numReadList + 1 as number
end repeat

---イベントの中を整形
set theChl to "BEGIN:VEVENT%0ALOCATION:" & theLocation & "%0ADESCRIPTION:" & theDescription & "%0AURL:" & theURL & "%0ASUMMARY:" & theSummary & "%0ASEQUENCE:" & theSequence & "%0A" & theDTSTART & "%0A" & theDTEND & "%0AEND:VEVENT" as text
log theChl
---QRコードを生成
--BASE URL
set theApiUrl to "https://chart.googleapis.com/chart?" as text

set theCht to "qr" as text

set theChs to "540x540" as text

set theChoe to "UTF-8" as text

---L M Q R
set theChld to "L" as text

--URLを整形
set theOpenUrl to ("" & theApiUrl & "&cht=" & theCht & "&chs=" & theChs & "&choe=" & theChoe & "&chld=" & theChld & "&chl=" & theChl & "") as text


-----サファリで開く
tell application "Safari"
activate
make new document with properties {name:"QR-CODE by Google API"}
tell window 1
open location theOpenUrl
end tell
end tell




to doReplace(theText, orgStr, newStr)
set oldDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to orgStr
set tmpList to every text item of theText
set AppleScript's text item delimiters to newStr
set tmpStr to tmpList as text
set AppleScript's text item delimiters to oldDelim
return tmpStr
end doReplace


---URLエンコードのサブルーチン
on encodeURL(str)
set scpt to ("python3 -c 'import urllib.parse;[print(urllib.parse.quote(\"" & str & "\", safe=\"/:;#!?=\"))]'") as text
return do shell script scpt
end encodeURL

|

その他のカテゴリー

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