系统日期在应用程序启动时验证
我在 OSX 10.6.7 下的 Xcode V3.2.6 中构建了一个基于 applescript 的应用程序。 我想在我的应用程序中添加额外的代码,以便当系统启动时,它会将我在应用程序中设置的日期与系统日期进行比较。 如果日期在指定范围内,则继续。如果日期检查超出范围,则立即终止程序。
目前代码看起来像这样:
on clicked the Object
if name of theObject = "One" then
try
display dialog "ONE"
end try
else if name of theObject = "two" then
try
display dialog "TWO"
end try
end if
end clicked
on action theObject
end action
这个论坛中一位非常好的用户 Chuck 发布了一些东西。该代码在 Apple scripter 下工作得很好,但当我粘贴到 Xcode 中时却不行。 谁能告诉我我做错了什么?
查克发布
set range to 3 * days
set targetDate to (date "Saturday, March 19, 2011 12:00:00 AM")
set currDate to current date
if abs(targetDate - currDate) > range then
display dialog "quit"
else
display dialog "continue"
end if
on abs(n)
if n < 0 then
return -n
else
return n
end if
end abs
非常感谢!
I have built an applescript based app in Xcode V3.2.6 under OSX 10.6.7.
I want to have additional code to my application so when the system launched, it will compare the date I set in the application with the system date.
If date within range specified, proceed. If date check is out of range then terminate program immediately.
currently the code looks something like this:
on clicked the Object
if name of theObject = "One" then
try
display dialog "ONE"
end try
else if name of theObject = "two" then
try
display dialog "TWO"
end try
end if
end clicked
on action theObject
end action
One of the very nice users in this fourm post Chuck has posted something. The code works great under apple scripter but not when I pasted into the Xcode.
Can any one tell me what I am doing wrong?
posted by Chuck
set range to 3 * days
set targetDate to (date "Saturday, March 19, 2011 12:00:00 AM")
set currDate to current date
if abs(targetDate - currDate) > range then
display dialog "quit"
else
display dialog "continue"
end if
on abs(n)
if n < 0 then
return -n
else
return n
end if
end abs
Thanks so much!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经很长时间没有使用以前称为 AppleScript Studio 的技术了。 :) 但是,我刚刚创建了一个 Cocoa-AppleScript 应用程序,我看到文件
UntitledAppDelegate.applescript
默认情况下具有以下内容:请注意
on applicationWillFinishLaunching_
处理程序和放置的注释Xcode 那里。这是您要放置在程序启动时执行的代码的位置。例如,我在其中放置了一个beep
语句,应用程序在启动时会发出蜂鸣声。所以我猜你可能有这样的东西:It's been a long time since I worked with the technology formerly known as AppleScript Studio. :) However, I just created a Cocoa-AppleScript application and I see that the file
UntitledAppDelegate.applescript
has the following by default:Note the
on applicationWillFinishLaunching_
handler and the comment placed there by Xcode. This is where you want to place code that will execute when the program launches. For example, I placed abeep
statement in there and the application beeped when it launched. So I'm guessing you could have something like this: