Calendar

[Excel]カレンダー生成(曜日・祝日入り)GoogleAPI

こんな感じのカレンダーを生成します

202211071580x531



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

property refMe : a reference to current application
property refNSString : a reference to refMe's NSString
property refNSData : a reference to refMe's NSData
property refNSURL : a reference to refMe's NSURL
property refNSDictionary : a reference to refMe's NSDictionary
property refNSMutableDictionary : a reference to refMe's NSMutableDictionary
property refNSJSONSerialization : a reference to refMe's NSJSONSerialization

property refNSDate : a reference to refMe's NSDate
property refNSDateComponents : a reference to refMe's NSDateComponents
property refNSCalendar : a reference to refMe's NSCalendar
property refNSDateFormatter : a reference to NSDateFormatter


####設定項目
set numFontSize to 10.5 as number
##set strFontName to "Osaka−等幅" as text
set strFontName to "Arial Unicode MS" as text
##set strFontName to "メイリオ" as text


###APIkey
set strApiKye to "XXXXXXXXXXXXXXXXXXXXXXXX"


########################
#####ここから処理
####日付情報の取得--> 今の『年』の数値を求める
set ocidDate to refNSDate's |date|()
set ocidCalendar to refNSCalendar's autoupdatingCurrentCalendar()
set ocidCalendarUnitYear to refMe's NSCalendarUnitYear
set ocidCalendarUnitMonth to refMe's NSCalendarUnitMonth
set ocidDateComponents to ocidCalendar's components:((ocidCalendarUnitYear) + (ocidCalendarUnitMonth)) fromDate:ocidDate
set numSetYear to (ocidDateComponents's |year|) as integer
set numSetMonth to (ocidDateComponents's |month|) as integer
#####各種リスト
set listWeekDay to {"", "", "", "", "", "", ""} as list
set listYear to {(numSetYear - 1), (numSetYear), (numSetYear + 1)} as list
set listMonth to {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12} as list
########################
#####年ダイアログを出す
try
set objResponseYear to (choose from list listYear with title "年選択" with prompt "年を選択してください" default items (item 2 of listYear) OK button name "OK" cancel button name "キャンセル" with multiple selections allowed without empty selection allowed)
on error
log "エラーしました"
return
end try
if objResponseYear is false then
return
end if
set numSetYear to (objResponseYear) as integer
########################
#####月ダイアログを出す
if numSetMonth = 12 then
set numSetMonth to 1 as integer
else
set numSetMonth to numSetMonth + 1 as integer
end if
try
set objResponseMonth to (choose from list listMonth with title "月選択" with prompt "月を選択してください" default items (item (numSetMonth) of listMonth) OK button name "OK" cancel button name "キャンセル" with multiple selections allowed without empty selection allowed)
on error
log "エラーしました"
return
end try
if objResponseMonth is false then
return
end if
set numSetMonth to (objResponseMonth) as integer

########################
#####日付コンポーネント初期化
set ocidDateComponents to refNSDateComponents's alloc()'s init()
ocidDateComponents's setYear:numSetYear
ocidDateComponents's setMonth:numSetMonth

########################
###エクセルの基本処理
set strMonthNoZeroSupp to (text -2 through -1 of ("00" & numSetMonth)) as text
set strSheetName to ("" & numSetYear & "-" & strMonthNoZeroSupp & "") as text
set strFileName to ("" & strSheetName & "カレンダーxlsx") as text
set strDesktopPath to POSIX path of (path to desktop folder from user domain) as text
set strSaveFilePath to (strDesktopPath & strFileName) as text
####新規ワークブック
tell application "Microsoft Excel"
activate
set objWorkBook to make new workbook with properties {excel 8 compatibility mode:false}
tell objWorkBook
set strWorkBookName to name as text
end tell
end tell
####シートの名前の変更
tell application "Microsoft Excel"
tell objWorkBook
tell active sheet
set name to strSheetName
end tell
end tell
end tell
###A1 左上のセルの処理
tell application "Microsoft Excel"
tell objWorkBook
tell sheet strSheetName
tell cell "A1"
set number format to "@"
###Aに年月を入力
set value to ("" & (numSetYear as text) & "/" & strMonthNoZeroSupp) as text
####タイトル行の処理
tell cell "$1:$1"
tell font object
set font size to numFontSize
set name to strFontName
set color to {0, 0, 0}
end tell
tell interior object
set color to {255, 255, 255}
end tell
tell border id border top
set color to {0, 0, 0}
#set color index to color index automatic
set line style to continuous
set weight to border weight thin
#set tint and shade to 0.0
end tell
tell border id border bottom
set color to {0, 0, 0}
#set color index to color index automatic
set line style to continuous
set weight to border weight thin
#set tint and shade to 0.0
end tell
tell border id border left
set color to {0, 0, 0}
#set color index to color index automatic
set line style to continuous
set weight to border weight thin
#set tint and shade to 0.0
end tell
tell border id border right
set color to {0, 0, 0}
#set color index to color index automatic
set line style to continuous
set weight to border weight thin
#set tint and shade to 0.0
end tell
end tell
end tell
end tell
end tell
end tell
########################
###日付
set ocidDate to refNSCalendar's currentCalendar's dateFromComponents:ocidDateComponents
####日付のカレンダーの『レンジ』
set ocdiMaxDateRange to refNSCalendar's currentCalendar's rangeOfUnit:(refMe's NSDayCalendarUnit) inUnit:(refMe's NSMonthCalendarUnit) forDate:ocidDate

########################
###祭日処理
###URL
set strURL to "https://www.googleapis.com/calendar/v3/calendars/" as text
set strCalendarID to "ja.japanese%23holiday%40group.v.calendar.google.com" as text
###
set strTimeZone to "T00%3A00%3A00.000Z"
set strTimeMin to "" & numSetYear & "-01-01" & strTimeZone as text
set strTimeMax to "" & numSetYear & "-12-31" & strTimeZone as text

set strURL to (strURL & strCalendarID & "/events?timeMax=" & strTimeMax & "&timeMin=" & strTimeMin & "&key=" & strApiKye) as text
########################
#####################
###NSURL
set ocidJsonURL to (refNSURL's URLWithString:strURL)
###URLの内容を読み込む
set listDownLoadData to refNSData's dataWithContentsOfURL:ocidJsonURL options:0 |error|:(reference)
-->戻り値がList
####JSONのデータ部
set ocidJsonData to (item 1 of listDownLoadData)
####エラー情報
set ocidNSErrorData to item 2 of listDownLoadData
if ocidNSErrorData is not (missing value) then
doGetErrorData(ocidNSErrorData)
return "エラー"
end if
#####################
###JSON初期化
set listJSONSerialization to (refNSJSONSerialization's JSONObjectWithData:ocidJsonData options:0 |error|:(reference))
set ocidJsonData to item 1 of listJSONSerialization
#####レコードに格納
set ocidJsonResponse to (refNSDictionary's alloc()'s initWithDictionary:ocidJsonData)

#####################
###使いやすいようなレコードを作成
set ocidHolidayDictionary to refNSMutableDictionary's alloc()'s initWithCapacity:0
###参照
####items
set ocidItemsArray to ocidJsonResponse's valueForKey:"items"

repeat with ocidArrayItems in ocidItemsArray
###祝日名
set strSummary to (ocidArrayItems's valueForKey:"summary") as text
###日付
set strDate to ((ocidArrayItems's valueForKey:"start")'s valueForKey:"date") as text
(ocidHolidayDictionary's setObject:strSummary forKey:strDate)

end repeat



########################
###日付毎処理
set numCntRows to 2

repeat with numDayNo from (location of ocdiMaxDateRange) to (|length| of ocdiMaxDateRange)
-->ここまでは年と月でのカレンダーなので
###日付を入れて
(ocidDateComponents's setDay:numDayNo)
set ocidDate to (refNSCalendar's currentCalendar's dateFromComponents:ocidDateComponents)
set ocidWeekDayClender to (refNSCalendar's currentCalendar's components:(refMe's NSWeekdayCalendarUnit) fromDate:ocidDate)
###日付
log ocidDate as date
###日付番号
log numDayNo
set strDayNoZeroSupp to (text -2 through -1 of ("00" & numDayNo)) as text
#####################
###曜日処理
set numWeekDayNo to (ocidWeekDayClender's |weekday|)'s intValue()
###曜日番号
log numWeekDayNo
###曜日テキスト
set strWeekDayJp to (item numWeekDayNo of listWeekDay) as text
###祭日取得用
set strDateText to ("" & numSetYear & "-" & strMonthNoZeroSupp & "-" & strDayNoZeroSupp & "") as text
###祭日取得
set strValue to (ocidHolidayDictionary's valueForKey:strDateText) as text
###祭日処理
if strValue is "missing value" then
set numChkHoliday to 0 as integer
else
set numChkHoliday to 1 as integer
####Cの列
set strCellNoHoliday to ("C" & numCntRows & "") as text
tell application "Microsoft Excel"
tell objWorkBook
tell sheet strSheetName
tell cell strCellNoHoliday
###Cの列に祭日名を入力
set value to (strValue as text)
end tell
end tell
end tell
end tell
end if

###セル番号
set strCellNoDay to ("A" & numCntRows & "") as text
set strCellNoWeek to ("B" & numCntRows & "") as text
set strCellRowsRange to "$" & numCntRows & ":$" & numCntRows & ""

########################
###エクセル処理
tell application "Microsoft Excel"
tell objWorkBook
tell sheet strSheetName
tell cell strCellNoWeek
set value to strWeekDayJp
end tell
tell cell strCellNoDay
set value to strDayNoZeroSupp
end tell
end tell
end tell
#######行処理
tell cell strCellRowsRange
set number format to "@"
#####
tell interior object
if numWeekDayNo = 1 then
set color to {254, 188, 190}
else if numWeekDayNo = 7 then
set color to {212, 243, 255}
else if numChkHoliday = 1 then
set color to {254, 188, 190}
else
set color to {255, 255, 255}
end if
end tell
#####
tell font object
set font size to numFontSize
set name to strFontName
if numWeekDayNo = 1 then
set color to {170, 0, 0}
else if numWeekDayNo = 7 then
set color to {0, 88, 176}
else if numChkHoliday = 1 then
set color to {170, 0, 0}
else
set color to {0, 0, 0}
end if
end tell
tell border id border top
set color to {0, 0, 0}
#set color index to color index automatic
set line style to continuous
set weight to border weight thin
#set tint and shade to 0.0
end tell
tell border id border bottom
set color to {0, 0, 0}
#set color index to color index automatic
set line style to continuous
set weight to border weight thin
#set tint and shade to 0.0
end tell
tell border id border left
set color to {0, 0, 0}
#set color index to color index automatic
set line style to continuous
set weight to border weight thin
#set tint and shade to 0.0
end tell
tell border id border right
set color to {0, 0, 0}
#set color index to color index automatic
set line style to continuous
set weight to border weight thin
#set tint and shade to 0.0
end tell
end tell
end tell

set numCntRows to numCntRows + 1
end repeat

|

[Json]祝祭日の取得 GoogleAPI版

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

property refMe : a reference to current application
property refNSString : a reference to refMe's NSString
property refNSData : a reference to refMe's NSData
property refNSURL : a reference to refMe's NSURL
property refNSDictionary : a reference to refMe's NSDictionary
property refNSJSONSerialization : a reference to refMe's NSJSONSerialization
property refNSMutableDictionary : a reference to refMe's NSMutableDictionary


###APIkey
set strApiKye to "XXXXXXXXXXXXXXXXXXXXXXXX" as text

###URL
set strURL to "https://www.googleapis.com/calendar/v3/calendars/" as text
set strCalendarID to "ja.japanese%23holiday%40group.v.calendar.google.com" as text

###
set strTimeZone to "T00%3A00%3A00.000Z"
set strTimeMin to "2023-01-01" & strTimeZone as text
set strTimeMax to "2023-12-31" & strTimeZone as text


set strURL to (strURL & strCalendarID & "/events?timeMax=" & strTimeMax & "&timeMin=" & strTimeMin & "&key=" & strApiKye) as text
log strURL

#####################
###NSURL
set ocidJsonURL to (refNSURL's URLWithString:strURL)
###URLの内容を読み込む
set listDownLoadData to refNSData's dataWithContentsOfURL:ocidJsonURL options:0 |error|:(reference)
-->戻り値がList
####JSONのデータ部
set ocidJsonData to (item 1 of listDownLoadData)
####エラー情報
set ocidNSErrorData to item 2 of listDownLoadData
if ocidNSErrorData is not (missing value) then
doGetErrorData(ocidNSErrorData)
return "エラー"
end if
#####################
###JSON初期化
set listJSONSerialization to (refNSJSONSerialization's JSONObjectWithData:ocidJsonData options:0 |error|:(reference))
set ocidJsonData to item 1 of listJSONSerialization
#####レコードに格納
set ocidJsonResponse to (refNSDictionary's alloc()'s initWithDictionary:ocidJsonData)

#####################
###使いやすいようなレコードを作成
set ocidHolidayDictionary to refNSMutableDictionary's alloc()'s initWithCapacity:0
###参照
####items
set ocidItemsArray to ocidJsonResponse's valueForKey:"items"

repeat with ocidArrayItems in ocidItemsArray
###祝日名
set strSummary to (ocidArrayItems's valueForKey:"summary") as text
###日付
set strDate to ((ocidArrayItems's valueForKey:"start")'s valueForKey:"date") as text
(ocidHolidayDictionary's setObject:strSummary forKey:strDate)

end repeat

-->祝日レコード
log ocidHolidayDictionary as record




to doGetErrorData(ocidNSErrorData)
#####個別のエラー情報
log "エラーコード:" & ocidNSErrorData's code() as text
log "エラードメイン:" & ocidNSErrorData's domain() as text
log "Description:" & ocidNSErrorData's localizedDescription() as text
log "FailureReason:" & ocidNSErrorData's localizedFailureReason() as text
log ocidNSErrorData's localizedRecoverySuggestion() as text
log ocidNSErrorData's localizedRecoveryOptions() as text
log ocidNSErrorData's recoveryAttempter() as text
log ocidNSErrorData's helpAnchor() as text
set ocidNSErrorUserInfo to ocidNSErrorData's userInfo()
set ocidAllValues to ocidNSErrorUserInfo's allValues() as list
set ocidAllKeys to ocidNSErrorUserInfo's allKeys() as list
repeat with ocidKeys in ocidAllKeys
if (ocidKeys as text) is "NSUnderlyingError" then
log (ocidNSErrorUserInfo's valueForKey:ocidKeys)'s localizedDescription() as text
log (ocidNSErrorUserInfo's valueForKey:ocidKeys)'s localizedFailureReason() as text
log (ocidNSErrorUserInfo's valueForKey:ocidKeys)'s localizedRecoverySuggestion() as text
log (ocidNSErrorUserInfo's valueForKey:ocidKeys)'s localizedRecoveryOptions() as text
log (ocidNSErrorUserInfo's valueForKey:ocidKeys)'s recoveryAttempter() as text
log (ocidNSErrorUserInfo's valueForKey:ocidKeys)'s helpAnchor() as text
else
####それ以外の値はそのままテキストで読める
try
log (ocidKeys as text) & ": " & (ocidNSErrorUserInfo's valueForKey:ocidKeys) as text
end try
end if
end repeat

end doGetErrorData

|

[QR]カレンダーのQRコード生成

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


property refMe : a reference to current application
property refNSString : a reference to refMe's NSString
property refNSMutableString : a reference to refMe's NSMutableString
property refNSMutableDictionary : a reference to refMe's NSMutableDictionary
property refNSURL : a reference to refMe's NSURL
property refNSBitmapImageRep : a reference to refMe's NSBitmapImageRep


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

###起動
tell application "Calendar" to launch
###前面に
tell application "Calendar" to activate
###起動チェック
repeat
tell application "Calendar"
set boolFrontMost to frontmost
end tell
if boolFrontMost is true then
######更新
tell application "Calendar"
activate
reload calendars
delay 0.5
end tell
exit repeat
end if
delay 1
end repeat
######更新(念には念を入れて)
tell application "Calendar"
activate
tell application "System Events"
keystroke "r" using command down
end tell
delay 0.5
end tell


######Plist読み込み
set strPlistFilePath to "~/Library/Preferences/com.apple.iCal.plist"
set ocidRelativePath to refNSString's stringWithString:strPlistFilePath
set ocidPlistFullPath to ocidRelativePath's stringByStandardizingPath
set ocidPlistPathURL to refNSURL's alloc()'s initFileURLWithPath:ocidPlistFullPath
set listReadPlistData to refNSMutableDictionary's dictionaryWithContentsOfURL:ocidPlistPathURL |error|:(reference)
set ocidPlistDict to item 1 of listReadPlistData
####カレンダーは基本選択していないって事は無いのでエラー制御不要?
set strSelectedListUUID to (ocidPlistDict's valueForKey:"last selected calendar list item") as text

set ocdiSelectedEventsArray to ((ocidPlistDict's valueForKey:"SelectedEvents")'s valueForKey:"iCal")
#####ocdiSelectedEventsArrayが空ならイベントを選択していない
if (count of ocdiSelectedEventsArray) = 0 then
return "イベントを選択してから実行してください"
error "イベントを選択してから実行してください" number -200
else if (count of ocdiSelectedEventsArray) ≥ 2 then
return "QRコードは1回に1コのイベント選択でお願いします"
error "QRコードは1回に1コのイベント選択でお願いします" number -201
end if
set strSelectedEventUUID to item 1 of ocdiSelectedEventsArray as text

####################
#####イベントの各種情報を取得
tell application "Calendar"
activate
########カレンダーID
tell calendar id (strSelectedListUUID)
get name
get color
get writable
get description
########イベントID
tell event id (strSelectedEventUUID)
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
#######################################
######取得したデータをVカード用に整形

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 ("LOCATION:" & theLocation) as text
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 ("DESCRIPTION:" & theDescription) as text
end if
set theURL to ("URL;VALUE=URI:" & theURL) as text
set theALARM to "BEGIN:VALARM\nTRIGGER:-PT1H\nATTACH;VALUE=URI:Chord\nACTION:AUDIO\nEND:VALARM"

####イベントを整形
set strEventText to "BEGIN:VEVENT\n" & "\n" & theSummary & "\n" & theLocation & "\n" & theSequence & "\n" & theDTSTART & "\n" & theURL & "\n" & theDescription & "\n" & theDTEND & "\n" & theALARM & "\nEND:VEVENT" as text
set ocidEventString to refNSString's stringWithString:strEventText

################################
###QRコードを保存するフォルダ
###ピクチャーフォルダのパス
set strSaveDirPath to "~/Pictures/QRcode"
set ocidSaveDirPath to refNSString's stringWithString:strSaveDirPath
set ocidSaveDirFullPath to ocidSaveDirPath's stringByStandardizingPath
set ocidSaveDirPathURL to refNSURL's alloc()'s initFileURLWithPath:ocidSaveDirFullPath
###作るフォルダの属性
(*
###主要なモード NSFilePosixPermissions
777-->511
775-->509
770-->504
755-->493
750-->488
700-->448
555-->365
333-->219
#####NSFileGroupOwnerAccountID
ゲストのGID
201-->_guest
99-->_unknown
-2-->nobody
*)
###途中のフォルダも作る
set boolMakeNewFolder to (objFileManager's createDirectoryAtURL:ocidSaveDirPathURL withIntermediateDirectories:true attributes:({NSFilePosixPermissions:511}) |error|:(reference))

################################
###ファイル名は日付時間
####日付フォーマット
set prefDateFormat to "yyyyMMddHHmmss"
set ocidFormatter to refMe's NSDateFormatter's alloc()'s init()
ocidFormatter's setLocale:(refMe's NSLocale's localeWithLocaleIdentifier:"ja_JP_POSIX")
ocidFormatter's setDateFormat:(prefDateFormat as string)
set strDateAndTime to (ocidFormatter's stringFromDate:(current date)) as text
#####日付をファイル名にする
set strSaveFileName to ("" & strDateAndTime & ".tif") as text
#####ディレクトリURLにファイル名足して保存先URL
set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:strSaveFileName


################################
###QRコード生成
####イベントデータをUTF8に確定
set ocidUtf8InputString to ocidEventString's dataUsingEncoding:(refMe's NSUTF8StringEncoding)
####CIQRCodeGenerator初期化
set ocidQRcodeImage to refMe'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 refMe's CGAffineTransform's CGAffineTransformMakeScale(numWidth, numHight)
##変換スケールを適応(元のサイズに元のサイズのスケール適応しても意味ないけど
set ocidCIImageScaled to ocidCIImage's imageByApplyingTransform:recordScalse
#######元のセルが1x1pxの最小サイズで出したいときはここで処理
##set ocidCIImageScaled to ocidCIImage
###イメージデータを展開
set ocidNSCIImageRep to refMe's NSCIImageRep's imageRepWithCIImage:ocidCIImageScaled
###出力用のイメージの初期化
set ocidNSImageScaled to refMe'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 refMe'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

##########################################################################
set ocidColorSpaceName to refMe's NSCalibratedWhiteColorSpace
set ocidNSBitmapImageFileType to refMe's NSBitmapImageFileTypeTIFF
set ocidBitmapFormat to refMe's NSBitmapFormatAlphaNonpremultiplied

###左右に4セル分づつ余白 quiet zoneを足す
####まずは元のQRコードのサイズに8セルサイズ分足したサイズの画像を作って
set ocidNSBitmapImagePadRep to (refNSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:numPadWidth pixelsHigh:numPadHight bitsPerSample:8 samplesPerPixel:1 hasAlpha:false isPlanar:false colorSpaceName:(ocidColorSpaceName) bitmapFormat:(ocidBitmapFormat) bytesPerRow:0 bitsPerPixel:0)
log ocidNSBitmapImagePadRep
###初期化
refMe's NSGraphicsContext's saveGraphicsState()
###ビットマップイメージ
(refMe's NSGraphicsContext's setCurrentContext:(refMe's NSGraphicsContext's graphicsContextWithBitmapImageRep:ocidNSBitmapImagePadRep))
###塗り色
set ocidSetColor to refMe's NSColor's colorWithWhite:1.0 alpha:1.0
ocidSetColor's |set|()

###画像にする
refMe'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:(refMe's NSCompositeSourceOver) fraction:1.0 respectFlipped:true hints:(missing value)
####画像作成終了
refMe's NSGraphicsContext's restoreGraphicsState()


#####################################
set ocidNSBitmapImageRepPropertyKey to refNSMutableDictionary's alloc()'s initWithCapacity:0
####TIFF用の圧縮プロパティ(NSImageCompressionFactor)
ocidNSBitmapImageRepPropertyKey's setObject:0 forKey:(refMe's NSImageCompressionFactor)

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

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



###ここから出来上がったファイルについて

###
tell application "Finder"
select (ocidSaveFilePathURL as alias)
end tell
###
tell application "Preview"
launch
activate

open (ocidSaveFilePathURL as alias)

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

######日付関連(カレンダー専用)
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コードを生成 改良版

[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

|

[AppleScript]イベント・カレンダー登録用のQRコードを作る(Google Chart利用)

こちらの記事の修正版
【QR】イベント・カレンダー登録用のQRコードを作る(Google Chart利用)
https://force4u.cocolog-nifty.com/skywalker/barcode2d/index.html

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

icsカレンダーファイルを選択すると
イベント登録用のQRコードを生成します
20220106171043

Img_0068


(*

make_qrcode4_eventfile.scpt
イベント登録用のQRを作成します。
たぶんiOS専用 

20190714 初回作成
20190715 phpのエラー処理追加
20220106 phpでの%エンコードの処理をpython3に置き換え
20220122 繰り返しイベントのSEQUENCEを追加 処理を一部修正

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


*)


on run
set theWithPrompt to "QRコードを作成します。"
set theDefLoc to path to downloads folder from user domain
set theFileType to "public.vcard,com.apple.ical.ics,public.calendar-event,public.ics,com.apple.ical.vcs" as text
set AppleScript's text item delimiters to {","}
set theFileTypeList to every text item of theFileType
open (choose file default location theDefLoc ¬
with prompt theWithPrompt ¬
of type theFileTypeList ¬
without invisibles)
end run



on open DropObj
set theFilePath to POSIX path of DropObj
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


--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


end open


--------------文字の置き換えサブルーチン
to doReplace(theText, theOrgStr, theNewStr)
set theOldDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to theOrgStr
set theTmpList to every text item of theText
set AppleScript's text item delimiters to theNewStr
set theReplaceStr to theTmpList as text
set AppleScript's text item delimiters to theOldDelim
return theReplaceStr
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

|

その他のカテゴリー

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