Toggle enable/disable for Automator app - applescript

I've got a monstrously large Automator application designed to be used by others without advanced-level computer skills. Basically, at a couple of points, I'd like users to be prompted to enable or disable the action that follows. The closest answer I've seen is:
automator enable/disable/delete action in run applescript
This is promising - I'm guessing this applescript method is the way forward. But this works for Automator workflows, not applications. I know so little about Applescript - even if it is possible, I wouldn't know how to do it. Anybody have any ideas?

I suggest breaking up your huge workflow into smaller pieces.
One workflow can call other workflows, but workflows don't have a conditional statement. There is no way to do an if-statement, a conditional for a workflow.
Automator actions such as "Run Shell Script" and "Run AppleScript" both have conditionals in them (if-statements).
AppleScript allows the ability to call upon applications to get things done, and allows you to display simple dialogs.
Shell scripts allow you to go deep inside of OS X, harnessing the power of Unix to work for you.
Both AppleScript and shell scripting would be useful for you to add to your knowledge of Automator.
AppleScript was actually designed to work with Mac applications. Look at the application:
/Applications/Utilities/AppleScript Editor.app
Beginner's tutorial on AppleScript:
Beginner's tutorial on the Mac's Unix command-line:
-- Kaydell
kaydell#yahoo.com
http://learnbymac.com

Related

AutoHotkey - persistent keystroke expansion? - HotStrings

I am having trouble understanding how this product works. In the old days of Windows 3.1 and 95 I used these things called "hotkeys" where, no matter where I was in Windows, I could hit a certain key combination and it would happen. I assumed that was what this program did. Is it really just a scripting language?
I followed the "quick start" tutorial in the help file and it talks about creating a script and how to set strings for keystroke patterns to expand into. However, I created this simple script and put it in an AHK file on my Desktop:
::gsell::
Great Seller! A++++++++++++++++++++++++++++++++
Return
When I run the script from my desktop it appears to complete pretty much instantly, and of course it does nothing because I am on my desktop. I assumed there was some way to actually use these hotkeys in other applications, but it is not obvious to me and I've made a fair effort. Is this just an automation scripting language, or is there some simple way to set up some simple hotkeys and have them persist across applications?
Hotkeys and Hotstrings are available globally by default. Your issue with the expansion is likely because you have special characters that need to be escaped. Try the following:
::gsell::Great Seller{!} A{+}
; Simple Hotkey - Ctrl+F1
^F1::Msgbox, You pressed a hotkey
I decided to try an example from the help file and it did work. Apparently the place where I thought it was telling me the script was closed, was actually saying the script was still running, and it counts the number of seconds when you refresh. For some reason the text expansion is still not working, but this question is pretty much solved.

Use Automator as an Applescript learning tool?

I am trying to teach myself AppleScript. Is Automator based on AppleScript? It occurs to me that if there is a way to view the AppleScript "guts" of an Automator action, that would be a great learning tool. But is that possible?
Thanks!
The best way to learn AppleScript is indeed to learn by example. MacScripter is the best place to start, without any doubt. Checkout the tutorials section and follow threads. Most problems you come across are already answered at MacScripter.
Automator is not based on AppleScript, it uses ScriptingBridge and mostly private API's. ScriptingBridge is an alternative to AppleScript for Cocoa developers (Objective-C), the syntax differs however greatly from AppleScript.
In conclusion, Automator is certainly not the place to start learning AppleScript.
Go to the link below and look at the "AppleScript Tutorial for Beginners" series. It's how I learned. Also you have a folder full of applescripts if you want to see a variety of code. Find it here: /Library/Scripts/. Also, under the help menu of AppleScript Editor is the "Applescript language guide". Finally, you will have to learn the terminology of the scriptable applications, so in AppleScript Editor file menu choose "Open Dictionary..." and choose an application in the list to see its applescript terms.
http://macscripter.net/viewtopic.php?id=25631

Open an application in a space using applescripts

I am trying to create a script that will open an application in a specific "space". So let's say I am on space 1 working in the terminal and then I want to be able to open safari in space 4. Is there a way to do this?
I have done some searching and found only ways to set the system profile options. Maybe I should tell you my end goal in case what I am attempting is not possible.
I use a laptop and plugin in to multiple stations, home, office, and travel. I want to create different window layouts for each one. So I will need an apple script telling it to open applications in varios spaces and different dimensions. I hope this makes sense. Ask me for clarification if it doesn't thanks!
PS the answer doesn't necessarily have to be any applescript I just thought that would be the easiest way :)
Here's a list of applescript commands for Spaces. There's a couple things there that might help you.
It is possible to do some scripting of application Space preferences by using the scripting interface to the System Events.app. See the answer to a similar question here.
The easiest way I've found is via GUI scripting. Make sure the Spaces menu is active on the upper right of your computer. That lists the spaces by number. You can then just write a GUI script to select the menu item of the space you wish. That will switch to that space. Then do an activate Applescript to open the application there.
Let me know if you need sample code demonstrating this. I have some in Python + Appsscript that does this but I should be easily able to convert it back to Applescript proper if you need it.

General Question about a GUI to execute a batch file

I'm new to programming and have taken some classes in it so I'm not sure if this is possible. I want to use a COTS software called 010 Hex Editor and write a script for the program to automate a couple tasks. These tasks can be run from a batch file according to their documentation.
Then I want to instruct the user to eject the device and reinsert it to clear the cache. (This I want done just with a simple pop-up window.
Then I also want to format the device which I assume can be done in a batch file as it can be done through dos on Windows.
My question is, with these 3 steps, can I build a simple GUI that has a button that says, "Start" or something like that, then the pop up window comes up to eject and reinsert, and then another button to format, and another button to exit. I'm not really familiar with what language this could be done in, and how to do this as the C++/Java classes I've taken have been more about syntax and OOP. Thanks!
You can use the windows messenger service to put up an alert - but on newer windows (vista/7) it's a pain to set all the permissions to allow this.
There are lots of free utilities that will popup a dialog from the command line, with a given message and wait for a response.
They are generally called messagebox or msgbox - sorry can't recommend any in particular

AppleScript Editor record doesn't work

I have opened the AppleScript Editor and pressed Record button.
Then I run TextEdit, create a file and put some text there.
When I click the Stop button in AppleScript Editor, nothing was recorded, the window is blank.
What is the problem?
You can use the Record feature of the Automator to record the UI interaction steps needed to do the relevant workflow. Then you can then literally select and copy the recorded steps in automator and paste them into a new Applescript Editor window. This will give you applescript which may or may not work. You'll probably want/need to edit the resulting script, but at least it should help give an idea what is needed to achieve your workflow programatically. This method is usable regardless of whether or not the target application has an applescript dictionary or supports the AppleScript Editor Record button, as it is the interaction with the underlying UI elements which is recorded.
Steps:
Open Automator
Start a new "Workflow"
Start recording
Perform whatever steps you require with your app (in this case typing into textedit)
Stop recording
This will create a list of actions in Automator like:
Select all these and copy (CMD+c)
Open the Applescript Editor app
Paste (CMD+v). The result will be valid applescript to perform the actions you just recorded:
Note that as is generally the case with UI automation, the automator records steps exactly and the script plays them back exactly. This my not be exactly what you want - e.g. if a different application were active, the text could get typed in there instead. The generated applescript should be used as a guide to the final applescript.
The problem is that applications need to explicitly support AppleScript recording in order for it to work, but almost no applications actually do. Finder still supports it a bit, and maybe a couple other apps (BBEdit comes to mind), but for the most part, AppleScript recording has been pretty useless for quite some time.
Not all apps are recordable (in fact, only a small handful are). Recordablity is something each app needs to implement, and I guess TextEdit isn't recordable.

Resources