在自定义Automator Action中保存用户弹出式选择 [英] Save a user popup selection in a custom Automator Action

查看:253
本文介绍了在自定义Automator Action中保存用户弹出式选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Xcode 5. *进行可可应用程序自动化操作。
接口是一个简单的弹出菜单,使用一个插座填充:

 告诉PopupMenu removeAllItems $ b告诉popupMenu为addItemsWithTitles_(theList)

当操作用于工作流),我想下次它运行,并且操作对话框显示(我将有选项:运行时显示选择),我想弹出菜单将选择更改为选择的最后一个。现在,默认的第一个项目显示,即使最后一次运行,用户在弹出菜单中选择了不同的项目。
我的想法是,我需要捕获在弹出菜单中的一个发送操作处理程序的更改,然后设置某种类型的默认。我有一个工作处理程序:

  onPopupMenuSentAction_(sender)
设置popupValue为(popupSelectedValue我的参数作为字符串
- 保存此选择某处?
end

正确的保存方式是什么?我使用用户默认值吗?我的绑定都是通过参数对象/控制器绑定。如果我应该使用用户默认值,有人可以给示例代码设置用户默认值,然后如何获取和设置一个新的值使用Cocoa-Applescript?



如果我可以得到保存在某处的菜单项的名称字符串,我可以获取该字符串,然后更改

中的弹出菜单的选择

 打开{} 
- 设置操作界面
end



感谢任何帮助,
Joe

解决方案

我有点不同。我会假设你指的是什么XCode称为弹出按钮(有点误导)。我没有使用参数,虽然这可能更好的大型项目。看看代码:

 脚本Insert_Picture_into_Powerpoint_Slide_Show 
属性parent:classAMBundleAction
属性menuChoices :{Insert a Beginning,I​​nsert at End}
属性menuSelection:缺失值
if(menuSelection as string)是缺失值
set menuSelection to 0 as integer - 设置默认值
end如果
结束脚本




  1. 我将内容值绑定到文件的所有者,并在模型键路径下放置 menuChoices


  2. p>然后,您只需将所选索引绑定到文件所有者,并将 menuSelection 添加到模型键路径类型。




默认值



在初始运行时,如果用户未点击任何内容,menuSelection将缺少值。因为我找不到一个办法,我创建了一个条件,它测试这个,并将其设置为默认的第一选择(当添加操作时显示的)。



当用户选择其中一个菜单选项时,系统会记住连续运行的选项。


Using Xcode 5.* for a cocoa-applescript automator action. Interface is a a simple popup menu that gets populated using an outlet with:

tell thePopupMenu to removeAllItems()
tell thePopupMenu to addItemsWithTitles_(theList)

When the action is used in a workflow (a Service actually), I want the next time it is run and the action dialog shows up (I will have "Options:Show when run" selected), I want the popup menu to change the selection to the last one that was selected. Right now, the default first item shows, even though last time it was run, the user selected a different item in the popup menu. My thought was that I need to capture a change in the popup menu with a Sent Action handler, and then set some type of default. I have a working handler:

on thePopupMenuSentAction_(sender)
       set popupValue to (popupSelectedValue of my parameters()) as string
     -- save this selection somewhere???
end

What's the right way to save this? Do I use User Defaults? My Bindings are currenly all tied through Parameter object/controller. If I should use User Defaults, can someone give example code for setting up User Defaults, and then how to get and set a new value using Cocoa-Applescript?

If I can get the name string of the menu item saved somewhere, I can get the string and then change the selection of the popup menu in the

on opened {}
    -- set up the action interface
end

handler which gets called just before the action is displayed each time.

Thanks for any help, Joe

解决方案

I did mine a bit differently. I will assume you are referring to what XCode calls a "pop up button" (somewhat misleading). I did not use the parameters at all, although that is probably better for larger projects. Have a look at the code:

script Insert_Picture_into_Powerpoint_Slide_Show
    property parent : class "AMBundleAction"
    property menuChoices : {"Insert a Beginning", "Insert at End"}
    property menuSelection : missing value
    if (menuSelection as string) is "missing value"
        set menuSelection to 0 as integer -- sets default value
    end if
end script

  1. I bound Content Values to File's Owner and under Model Key Path I put menuChoices.

  2. Then you just bind the Selected Index to File's Owner and for the Model Key Path type menuSelection.

Defaults

On the initial run, if the user does not click anything, the menuSelection will be missing value. Because I couldn't find a way around this, I created a conditional which tests for this and sets it to the first choice by default (the one that is shown when you add the action).

When the user selections one of the menu choices, the choice is remembered on sequential runs.

这篇关于在自定义Automator Action中保存用户弹出式选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆