Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Applescript 日期选择器显示问题(主线程问题?)_Applescript_Applescript Objc_Nsalert_Nsdatepicker - Fatal编程技术网

Applescript 日期选择器显示问题(主线程问题?)

Applescript 日期选择器显示问题(主线程问题?),applescript,applescript-objc,nsalert,nsdatepicker,Applescript,Applescript Objc,Nsalert,Nsdatepicker,正在使用来自的AppleScript文件 日期选择器不显示(至少在莫哈韦)。但是,如果我在runModal之前放置display alert,它确实会显示(但不是其他方式) 我理解这可能与后期Mac OSX版本中需要performSelectorOnMainThread有关,但如果是这种情况,我无法添加它以使代码正常工作。有什么想法吗?给你。。。真的没什么好说的。我基本上只是重写了它,因为我无法忍受凌乱的代码: # 06/04/16 09:35:02 # Author: Shane Stanle

正在使用来自的AppleScript文件

日期选择器不显示(至少在莫哈韦)。但是,如果我在
runModal
之前放置
display alert
,它确实会显示(但不是其他方式)


我理解这可能与后期Mac OSX版本中需要
performSelectorOnMainThread
有关,但如果是这种情况,我无法添加它以使代码正常工作。有什么想法吗?

给你。。。真的没什么好说的。我基本上只是重写了它,因为我无法忍受凌乱的代码:

# 06/04/16 09:35:02
# Author: Shane Stanley
# Adapted by Christopher Stone
# Fixed & Rewritten by CJK
--------------------------------------------------------------------------------
use framework "AppKit"
use scripting additions

property this : a reference to the current application
property nil : a reference to missing value
property _1 : a reference to reference

property NSAlert : a reference to NSAlert of this
property NSDatePicker : a reference to NSDatePicker of this
property NSView : a reference to NSView of this

property NSAlertSecondButtonReturn : 1001
property NSHourMinuteSecondDatePickerElementFlag : 14
property NSTextFieldAndStepperDatePickerStyle : 0
property NSYearMonthDayDatePickerElementFlag : 224
--------------------------------------------------------------------------------
property date : missing value
--------------------------------------------------------------------------------
on run
    its performSelectorOnMainThread:("showDatePicker:") withObject:{¬
        NSTextFieldAndStepperDatePickerStyle, ¬
        NSYearMonthDayDatePickerElementFlag + ¬
        NSHourMinuteSecondDatePickerElementFlag} ¬
        waitUntilDone:true

    return my date
end run

on showDatePicker:params
    local params

    set {PickerStyle, PickerElements} to params

    tell (current date) to set ¬
        [dateFrom, day, its month, day, year, time] to ¬
        [it, 1, 4, 1, 2015, 12 * hours + 0 * minutes]

    tell NSDatePicker's alloc()
        initWithFrame_({{0, 0}, {100, 100}})
        setDatePickerStyle_(PickerStyle)
        setDatePickerElements_(PickerElements)
        setDateValue_(dateFrom)
        set fittingSize to fittingSize()
        setFrameSize_(fittingSize)

        set View to NSView's alloc()
        View's initWithFrame:{{0, 0}, {100, 175}}
        View's setFrameSize:fittingSize
        View's addSubview:it

        tell NSAlert's alloc()
            init()
            setMessageText_("Pick a date and time")
            setInformativeText_("Any date")
            addButtonWithTitle_("OK")
            addButtonWithTitle_("Cancel")
            setAccessoryView_(View)

            runModal()
        end tell

        set my date to dateValue() as date
    end tell
end showDatePicker:
---------------------------------------------------------------------------❮END❯

系统信息:AppleScript版本:2.7系统版本:10.13.6

这看起来很棒,谢谢,我看到它在脚本编辑器中运行。我渴望将它与旧版本进行比较。但是首先--我可以问一下--你知道为什么在我从终端对这个文件使用
osascript datepicker.scpt
时,它不会运行吗?我现在已经将终端添加到系统首选项可访问性以及chmod 0755和
#/usr/bin/osascript
shebang,正如我在其他地方看到的那样,这些都不起作用。我相信这种脚本需要一个GUI环境来运行,以便能够绘制窗口、图形环境和视图。这意味着任何使用
osascript
执行其AppleScripts的程序也无法处理包含
NSWindow
NSView
WKWebView
和类似对象类的脚本,即使这些程序在GUI中运行。您基本上只限于脚本编辑器、脚本调试器和快速脚本,或者创建自己的AppleScript环境。我想要一个节点脚本来生成AppleScript并返回日期。在使用automator使用此AppleScript创建工作流后,我似乎可以执行
/usr/bin/automator datepicker.workflow
。看起来我甚至可以(正如所观察到的)使用Applescript文件构建自动机脚本的工作流。作为开源代码,我只希望构建过程是可重复和透明的。是的,我很乐意分享代码。我把我的一些代码放在同一个许可证下的GitHub上,所以让它投入使用很好。
# 06/04/16 09:35:02
# Author: Shane Stanley
# Adapted by Christopher Stone
# Fixed & Rewritten by CJK
--------------------------------------------------------------------------------
use framework "AppKit"
use scripting additions

property this : a reference to the current application
property nil : a reference to missing value
property _1 : a reference to reference

property NSAlert : a reference to NSAlert of this
property NSDatePicker : a reference to NSDatePicker of this
property NSView : a reference to NSView of this

property NSAlertSecondButtonReturn : 1001
property NSHourMinuteSecondDatePickerElementFlag : 14
property NSTextFieldAndStepperDatePickerStyle : 0
property NSYearMonthDayDatePickerElementFlag : 224
--------------------------------------------------------------------------------
property date : missing value
--------------------------------------------------------------------------------
on run
    its performSelectorOnMainThread:("showDatePicker:") withObject:{¬
        NSTextFieldAndStepperDatePickerStyle, ¬
        NSYearMonthDayDatePickerElementFlag + ¬
        NSHourMinuteSecondDatePickerElementFlag} ¬
        waitUntilDone:true

    return my date
end run

on showDatePicker:params
    local params

    set {PickerStyle, PickerElements} to params

    tell (current date) to set ¬
        [dateFrom, day, its month, day, year, time] to ¬
        [it, 1, 4, 1, 2015, 12 * hours + 0 * minutes]

    tell NSDatePicker's alloc()
        initWithFrame_({{0, 0}, {100, 100}})
        setDatePickerStyle_(PickerStyle)
        setDatePickerElements_(PickerElements)
        setDateValue_(dateFrom)
        set fittingSize to fittingSize()
        setFrameSize_(fittingSize)

        set View to NSView's alloc()
        View's initWithFrame:{{0, 0}, {100, 175}}
        View's setFrameSize:fittingSize
        View's addSubview:it

        tell NSAlert's alloc()
            init()
            setMessageText_("Pick a date and time")
            setInformativeText_("Any date")
            addButtonWithTitle_("OK")
            addButtonWithTitle_("Cancel")
            setAccessoryView_(View)

            runModal()
        end tell

        set my date to dateValue() as date
    end tell
end showDatePicker:
---------------------------------------------------------------------------❮END❯