2013-03-13 59 views
1

我試圖創建一個AppleScript腳本,將採取的日期形式:的AppleScript:轉換日期到一些有用的東西,然後進行計算

99年2月20日

然後,減5天從日期,並返回一個像這樣的日期:

99年2月15日

這裏是基本的AppleScript我有,但很明顯,我失去了周圍的日期轉換成某種邏輯,我可以操縱(並將其返回到人類可讀的東西)。

set itemPath to quoted form of POSIX path of theFile 

set dateString to do shell script "awk 'NR == 10 {print $3}' " & itemPath & " -" 
set myDueDate to dateString - (5 * days) 

set theTask to "Pay AMEX bill" 

tell application "OmniFocus" 
    tell front document 
     set theContext to first flattened context where its name = "OFFICE" 
     set theProject to first flattened context where its name = "Bookkeeping - PMS" 
     tell theProject to make new task with properties {name:theTask, context:theContext, due date:myDueDate} 
    end tell 
end tell 

在此先感謝!

回答

1

我覺得這些線應該是夠你需要的東西:

set dateString to "02/20/99" 

set thisDate to date dateString 
set fiveDaysEarlier to thisDate - 5 * days 
log date string of fiveDaysEarlier 
log short date string of fiveDaysEarlier 

此頁面具有強制轉換的轉換字符串時最新的類的對象支持更多的例子: AppleScript Class Reference: date

而且,它可能不言而喻,但字符串「02/20/99」不符合Y2k,所以猜測將不得不在某個地方作出這個日期在哪個世紀。

+0

return me「找不到對象」。編號-1728從日期「錯誤 – 2015-06-12 08:09:44

+0

@ chinna_82它仍然適用於我使用OS X 10.10.3終端上的AppleScript編輯器和osascript。您使用的是什麼OS X版本?是否將代碼文本完全複製並粘貼到AppleScript編輯器?哪行代碼導致錯誤? – 2015-06-12 22:19:41

0

如果您收到錯誤「FileMaker Pro got一個錯誤:找不到對象。「號碼-1728,加上我的日期。例如,

將此日期設置爲我的日期dateString。

在tell中工作時,我認爲它需要訪問tell範圍之外的方法。

相關問題