스크립트 목적 아래 스크립트는 Pashua라는 App을 사용하여 여러 입력을 반환하는 사용자 정의 대화 상자를 표시합니다. 이러한 입력은 새 달력 이벤트를 만드는 데 사용됩니다.
문제 내가 겪고있는 문제는 날짜가 YYYY-MM-DD 형식으로 반환된다는 것입니다. 날짜를 MM / DD / YYYY 형식으로 입력하면 아무런 문제없이 이벤트가 작성됩니다.
날짜를 올바르게 변환하려면 어떻게합니까?
다음은 도움이 필요한 코드 행입니다.
set sDate to (sDate of theResult)
--- Returns: 2018-12-12
set sTime to (sTime of theResult)
--- Returns: 10:00 AM
set eDate to (eDate of theResult)
--- Returns: 2018-12-12
set eTime to (eTime of theResult)
--- Returns: 11:00 AM
set eStart to date of (sDate & space & sTime)
--- Error: Can’t get date of 2018-12-12 10:00 AM
set eEnd to date of (eDate & space & eTime)
--- Error: Can’t get date of 2018-12-12 11:00 AM
나타나는 오류입니다.
전체 코드 :
-- Get the path to the folder containing this script
tell application "Finder"
set thisFolder to (container of (path to me)) as string
if "Pashua:Pashua.app:" exists then
-- Looks like the Pashua disk image is mounted. Run from there.
set customLocation to "/Users/dnaab/Applications/"
else
-- Search for Pashua in the standard locations
set customLocation to "/Users/dnaab/Applications/"
end if
end tell
try
set thePath to alias (thisFolder & "Pashua.scpt")
set pashuaBinding to load script thePath
tell pashuaBinding
-- Display the dialog
try
set pashuaLocation to getPashuaPath(customLocation)
set dialogConfiguration to my getDialogConfiguration(pashuaLocation)
set theResult to showDialog(dialogConfiguration, customLocation)
-- Display the result. The record keys ("... of theResult") are defined in the
-- dialog configuration string.
if {} = theResult then
display alert "Empty return value" message "It looks like Pashua had some problems using the window configuration." as warning
else if cb of theResult is not "1" then
set eCalendar to "Calendar"
set eSummary to (eSummary of theResult)
set eURL to (eURL of theResult)
set eDescription to (eDescription of theResult)
set sDate to (sDate of theResult)
set sTime to (sTime of theResult)
set eDate to (eDate of theResult)
set eTime to (eTime of theResult)
set sDate to date of (sDate & space & sTime)
set eDate to date of (eDate & space & eTime)
display dialog sDate buttons {"Cancel"} default button 1
tell application "Calendar"
tell calendar eCalendar
make new event with properties {summary:eSummary, start date:eStart, end date:eDate, url:eURL}
end tell
end tell
else
-- The cancelbutton (named "cb" in the config string) was pressed
(*
display dialog "The dialog was closed without submitting the values"
*)
end if
on error errorMessage
display alert "An error occurred" message errorMessage as warning
end try
end tell
on error errStr number errorNumber
display dialog errStr
end try
-- Returns the configuration string for an example dialog
on getDialogConfiguration(pashuaLocation)
if pashuaLocation is not "" then
set img to "img.type = image
img.x = 250
img.y = 260
img.maxwidth = 60
img.tooltip = This is an element of type “image”
img.path = /Applications/Calendar.app/Contents/Resources/App.icns"
else
set img to ""
end if
return "
# Set window title
*.title = New iCal Event
# Event Summary
eSummary.type = textfield
eSummary.label = Event Summary
eSummary.default = Calendar
eSummary.width = 310
eSummary.x = 1
eSummary.y = 310
# Add Start Date
sDate.type = date
sDate.label = Event Start Date
sDate.default = today
sDate.textual = 1
sDate.x = 1
sDate.y = 255
# Add Start Time
sTime.type = date
sTime.label = Event Start Time
sTime.default = today
sTime.time = 1
sTime.date = 0
sTime.textual = 1
sTime.width =70
sTime.x = 110
sTime.y = 255
# Add End Date
eDate.type = date
eDate.label = Event Start Date
eDate.default = today
eDate.textual = 1
eDate.x = 1
eDate.y = 200
# Add End Time
eTime.type = textfield
eTime.label = Event End Time
eTime.width = 70
eTime.x = 110
eTime.y = 200
# Add Calendar
eURL.type = textfield
eURL.label = URL
eURL.default = message://
eURL.width = 310
eURL.x = 1
eURL.y = 150
# Description
eDescription.type = textbox
eDescription.label = Description
eDescription.width = 310
eDescription.x = 1
eDescription.y =70
# Add a cancel button with default label
db.type = defaultbutton
cb.type = cancelbutton
"
end getDialogConfiguration
YYYY-MM-DD
체재? 우리가 스스로 테스트 할 수 있도록 관련 코드를 포함하십시오.