automator enable/disable/delete action in run applescript - applescript

I have an automator workflow with a Run Applescript action. Is it possible to enable/disable/delete another automator action in my Run Applescript? See my previous question for more details.
Edit: I have started a bounty. I am looking for questions that enable me to do this in an Automator application.

I'm not aware of a way to do it within an Automator application, but give this a try - the script in the following example workflow toggles the enabled property of the action following it. Create a new workflow with 3 actions:
1) an Ask for Text action to get some input;
2) a Run AppleScript action to test the input and do something:
on run {input, parameters}
if (input as text) is "" then -- if no input then disable the following action
set currentAction to index of current action of front workflow -- the most recent completed action
tell Automator action index (currentAction + 2) of front workflow to set enabled to not enabled
end if
return input
end run
3) an Ask for Confirmation action to put up a dialog (or not).
You can use other action properties such as the name, but the index or id works better if there are more than one of the same action.

Related

Mac Automator/Applescript(?) to extract URL's from Mail messages

I'm trying to get a text document list of any links in a bunch of email messages that reside in the latest Mac Mail.app (OS X 10.10.2 Yosemite), and am simply stumped.
I thought I'd be able to just...
Put a couple of Automator.app actions together in a Service/Workflow,
Select/highlight all the email messages within the Mail.app,
Select that Service or run that Workflow,
And have a text document with every URL/link that could be found within them all.
However, this didn't work.
I figured out how to do this with one email message at a time, but that's not what I want. attached is a screenshot of 3 workflows. The first one is the one that works with just one email message & highlighting all the text in it & running the Service. the other two just simply don't work.
I also notice that the the first shows up in the Service Menu with a single email open; once I highlight more than one email message, the option goes away from the Service menu.
Any tips or tricks?
I figured out how you could reach your goal, start with creating a new service within Automator (input: "No input", application: "Mail")
The first action is Get Selected Mail Messages (Get selected: messages)
The second action is Execute AppleScript with the following script:
on run {input, parameters}
set mailContentList to {}
tell application "Mail"
repeat with selectedMail in input
set end of mailContentList to content of selectedMail
end repeat
end tell
return mailContentList
end run
This script simply walks through the given messages, reads out the content and passes this list to the next action
The third action is Extract URLs from Text. This is listed as "Extract Data from Text" and one of the types of data is "URLs".
And the final action is New TextEdit Document
Save it with a nice name like Extract URLs from selected mails
After that the Service is available inside the Services menu inside the Mail app.
In my test I found a few internal URLs without http:// from links to anchors, so maybe you want to delete all URLs that do not start with http. You can do so by using another action before creating the new TextEdit document:
Filter Paragraphs with options "Paragraphs that start with http" (don't know how these parameters are called in English Automator, sorry)
Feel good, Michael / Hamburg

Adding a dialog child workflow to an on-demand workflow

I was wondering if anybody ran into the same issue as I am facing now.
What I'm trying to do is have a workflow that checks the condition of a field (optionset) of a form. If the field has option 1, 2 or 3 then create new record with certain shared attributes, otherwise start a child workflow. The child workflow is a "Dialog" process, not a "workflow" process which informs the user that the record was not created and why. For some reason I cannot select the dialog workflow from the dropdown list of available child workflows...
Both the parent workflow and the "dialog" workflow process are based on the same entity.
If anybody has any ideas on how I could debug this or any clues in general I would greatly appreciate your feedback.
Thanks for taking the time to read this post!
It is not possible to call a dialog from a workflow (see here).
Workflows are generally triggered by events.
Imagine the ramifications - which user would receive the dialog and what if no-one was logged in?
One option is to drive everything with JavaScript
Trigger on change of the option set
Create the records
Start the workflow
Start the dialog
See the section under the heading "Opening a Dialog Process by Using a URL" on MSDN here
Rather use the URL than showModalDialog or showModelessDialog.
What might work even better is to call an Action from JavaScript. The Action can run synchronously and create all records, start child workflows and dialogs.
A synchronous workflow can stop an event and return an error message to the user, but cannot return success messages - it look like this will not meet your requirements, but Gareth Tucker has an example here.

InstallShield (Windows Installer) Action Text not being updated for Custom Action

I'm using installshield to develop an installer for a product and I'm having issues with the ActionText (the current action description) updating for my custom action.
I've followed these steps here: http://helpnet.flexerasoftware.com/installshield17helplib/ActionTextSettings.htm which make perfect sense, and should work, but my custom action doesn't update the action text in the UI.
I'm thinking that because my custom action runs and waits for a long running process to end, maybe it's blocking whichever thread is responsible for updating the action text.
Now I write it, it doesn't seem to make sense, but I don't know what else might do it!
The main details of the Custom Action are:
Filename & Command line: wscript.exe "invisible.vbs" "longrunningbatch.bat"
Return Processing: Synchronous
In-Script Execution: Commit Execution in System Context
And invisible.vbs contains:
CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, True
The above line should hide the shell window and the 'True' ensures the shell doesn't return until the batch file has finished running.
I've also added my custom action to the Action Text list as per the link and associated it with a string.
Should work right?
Anyone else experienced this at all?
Firstly, you'll need to brush up on your Windows Installer, because if you've changed an action from commit to deferred and that's OK with you then you've done something unusual. Deferred actions are for actions that modify the system in some way related to the install. Commit actions are to finalise any work that the associated deferred action has done (e.g. deferred action modifies some system file. Commit action deletes the backup of the unmodified system file). Additionally, if you have a deferred action then you should also have a rollback action which undoes any action done by the deferred action in the event that the user cancels the install or it fails.
The following two links should help point you in the right direction:
http://blogs.flexerasoftware.com/installtalk/2011/10/i-take-it-all-back-using-windows-installer-msi-rollback-actions.html
http://www.installsite.org/pages/en/isnews/200108/index.htm
Secondly, if all the custom action does is to update the action text in the progress dialog, then you don't need it at all. Flexera doesn't document this, but you can set the action text for any custom action you build through the direct editor. To do this, add entries in the "ActionText" table, where the "Action" column is the name of your custom action and the "Description" column is the text you want to display.
Ok,
So I found this post: http://community.flexerasoftware.com/archive/index.php?t-82772.html, which basically says that since my custom action was set to commit execution, the install was effectively finished at the time it was running, and therefore there's no point in updating the progress text.
So the fix for my situation is to move my custom action to just before InstallFinalize and switch to 'deferred execution'.
Hope this might help someone.

Can an applescript "tell" call execute without visibly launching the application?

I have a Mail rule set up to launch the following applescript:
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
tell application "Mail"
-- do stuff, including...
CheckAddressBook(theName, theAddress)
end tell
end perform mail action with messages
end using terms from
on CheckAddressBook(theName, theAddress)
tell application "Address Book"
-- do stuff
end tell
end CheckAddressBook
Whenever this mail rule executes, it launches address book. Its not activated, but it suddenly shows up on my desktop. My question is, can tell blocks be instructed to launch the application silently, and quit when complete?
AppleScript can't control an application without it running. That's just the way it works. There are other methods you might use to access the Address Book database without launching the application, but if you're using AppleScript to get data from your Address Book database the application has to launch. My recommendation would be to simply add a quit command as suggested by Fábio.
To read the Address Book Database without launching "Address Book.app" I´d suggest to have a look at the command line tool "contacts" available for free here. You would then run it from Applescript like do shell script "/usr/bin/contacts Peter" and handle the values returned.

Automator / AppleScript to process incoming emails in Mac Mail

I'm designing an app that allows users to email me crash reports if my app ever crashes. I'd like to leave Mac Mail running on a computer and when an email comes through, an automator script / AppleScript runs to process the contents of the body of the email.
I've got the entire parsing/processing done in a python script, except I have to manually copy the contents of the email into a file and then run my parser on that file.
What's the best way to set this up so I can the contents of the email be pushed into my parsing script?
Many thanks!
Probably the simplest approach is to define a Mail.app Rule. You can set up filtering conditions to specify the set of incoming email to apply the rule to and among the rule actions you can specify is one to run an AppleScript on incoming messages. Rules are managed with Mail.app Preferences -> Rules. Apple supplies examples of Rule Action scripts with Mac OS X. Look in /Library/Scripts/Mail Scripts/Rule Actions or search the web.
Here's a script that extracts from email into a file using a mail rule: MacScripter / Mail rule script for message export. Might be good for sample code for what you're doing.
Use the Dictionary in Applescript Editor to see the properties of mail and you'll quickly be able to see the properties of any mail message. Here's a quick and dirty example of getting the content of a mail message.
tell application "Mail"
set the_messages to selection
repeat with this_message in the_messages
set mytext to content of this_message
end repeat
end tell
Modify the script linked to above that copies output to a temporary file and then pass that file to your Python script to act on.

Resources