Automator check file type - applescript

I've got an Ask for Finder Items Automator action. How do I make it check whether the file is an image?

Use "Filter Finder Items" and set a "Kind is image" rule.
I don't believe there is a way to perform a different action depending on the file type.

Related

AppleScript: multiple buttons in "choose from list"

I have a script which makes users choose from different options in a list. I want there to be three buttons; OK, Cancel and Help (display a dialog with guidance).
However, it seems that I cannot use the "buttons" parameter within a list.
So how do I add additional buttons? (with a custom name, that displays a dialogue)
Current script:
set MyList to {"A", "B", "C"}
set Chosen to
(choose from list MyList with title "Connect to"
with prompt "What do you want to connect to?"
OK button name "Connect" cancel button name "Abort" ---and help
with multiple selections allowed) as text
Unfortunately choose from list supports only two buttons.
Alternatives are a (second) standard dialog which opens the list dialog or an AppleScriptObjC app with a custom dialog window.
While choose from list only supports two buttons, you can use AppleScriptObjC to create very rich alerts/dialogs. I recommend starting with Shane Stanley's free Myriad Tables Lib. Here's an example:
To learn more, read Chapter 26:Richer Interfaces of Shane's excellent $15 book Everyday AppleScriptObjC, available here. You could also look at Dialog Toolkit on the same page. Because Cocoa alerts and dialogs provide an "accessory view", you can put many additional controls in there.

How to get selected files from TOpenDialog exactly in the order they were selected in?

I use a TOpenDialog component in Delphi XE7, because I want to select one or more files. However, after I select them and click OK, the selected files are stored already sorted alphabetically, from A to Z, in the Files property, thing which I do not want. I didn't see any switches or options neither in the TOpenDialog control, nor in the TStrings type.
How can I make this component store the selected files exactly in the order that I want to?
The underlying dialog box from the operating system doesn't keep track of that information (or if it does, it doesn't expose it in any way), and the wrapper class provided by Delphi doesn't synthesize it for you.
You can handle the OnSelectionChange event to deduce the selection order. Begin by creating your own ordered list to hold the selected files. When the event is triggered, inspect the dialog's Files property. Remove any entries from your internal list that aren't present in Files. For any items in Files that you don't already have, add them to the head of your list.
The system dialogs do not keep track of the order in which the items are selected. You have no way to get the system dialog to tell you that information. If you really need that then I see two options:
Write your own dialog that does keep track of order of selection.
Let the user specify order outside the file selection dialog.

Can I search for an object by its name within a form in VB6?

As declared in the title, for example, I want to search for a button whose name is button8, within a form where there are so many buttons that I do not want to check the name one by one.
Can I do this in VB6?
You should just be able to refer to the control via the controls collection, like so:
Me.Controls("Button8")
See this link.
Here's how to find a control in the form designer, if you know the name.
Go to the form designer, open the property window (press F4), and use the dropdown to choose the control. This shows the properties in the window (and you can edit them). It also selects the control onscreen.

IContextMenu:: QueryContextMenu and the "New" submenu item

Is it possible to have the "New" submenu (new folder, file ...) included in the menu queried by IContextMenu::QueryContextMenu?.
I didn't find a flag that seems to handle this need. I know that it`s possible to add an own menu but I rather want the shell sub menu.
Thanks,
SKAR

Automator: How do I use the Choose from List action?

I'm trying to create a Service using Automator that simply calls textutil convert. Eventually, I want to be able to right-click a docx file and convert to text, rtf, html, etc. After I right-click I want a very simple popup asking for the desired format.
I see the Choose from List action. It has no options. Somewhere I got the idea to make the input of Choose from List be Get Specified Text. I then tried putting my list of values in Get Specified Text. However, when I run it, I only get one line. I've tried one item per line, comma-delimited, space-delimited and even surrounding with curly braces, delimited with commas. Nothing works.
How do I get that chooser dialog to show all my options? Also, is there a way to restrict the selection to one item?
Thanks!
Here is the solution to select only one line in a list.
Remove ("Get Specified Text" and "Choose from List") actions.
Add the "Run AppleScript script" action. 1- Cut the text in the action. 2- Copy/paste this text in the action.
on run
choose from list {"TXT", "RTF", "RTFD", "HTML"} with prompt "Please make your selection" without multiple selections allowed and empty selection allowed
return the result as string
end run
The trick is to use an AppleScript variable!
The other suggested answers work, but the simplest and most straightforward way is to use an AppleScript variable to define the list choices.
A text variable can store only one item of plain text, but an AppleScript variable can be structured as an array, which is exactly what you need to define a list.
In the Variables Library, under Utilities, drag an
AppleScript variable into the Workflow above the Choose from List action.
Edit the Variable Options and define its Script as an array of text strings, containing your desired list of choices.
Remove the "Get Specified Text" action.
Add the "Run AppleScript" action above the "Choose from List" action.
In the "Run AppleScript" action, cut the text and copy/paste this text.
on run {}
set theList to {"TXT", "RTF", "RTFD", "HTML"}
return theList
end
You need to break up the text into a list of items, which is what Choose from List expects as input. You can use a Filter Paragraphs action to break up the text, for example return paragraphs that are not empty.
You don't mention what OS you are running, but Lion added the ability to use Rich Text in the text actions - unfortunately, most of the actions don't work as intended if they actually get Rich Text. In Lion, you can take advantage of some of the (hidden) input item coercions by using something like a Run Shell Script action (you don't need to put anything extra in there, just use the default, which passes items through) to convert Rich Text from the Get Specified Text action.
The Choose from List action has the All or None buttons, but there isn't a way to select a specified set of items. It is reasonably easy to write Automator actions, so rolling your own textutil wrapper would be another option.
There are also two Automator Actions that will also solve this problem.
One is Split Text which allow you to choose a certain delimiter to split the text.
The other is Get Words of Text which allows you to just get the individual words of text passed as input.
If you don't have these actions, you can get them from here:
https://itunes.apple.com/us/app/text-automator-actions-pack/id448838274?mt=12

Resources