What does «event coreslct» do in AppleScript - macos

I have an AppleScript source with this code:
«event coreslct» (last row of table X of document Y)
insert rows selection position below number of rows Z
The double angle brackets mean, the enclosed words are raw format or event code.
So my question is: what is the command of event code event coreslct...

The «event coreslct» as used in your example is specific to Microsoft Excel, and loosely translates to "select the cells concerned", or simply "select". To determine precisely what the definition of the command is you can perhaps try the instructions below:
According to Microsoft's KB:
To use the program-specific capabilities of Excel for Mac with
AppleScript, open and examine the AppleScript dictionary that is
supplied with Excel for Mac.
To use the Script Editor open the dictionary in Excel for Mac, follow
these steps:
1. Start the Script Editor. To do this, follow these steps:
a. Open your hard disk.
b. Open the Applications folder.
c. Open the AppleScript folder. For the Apple OS versions
earlier than OSX, open the Apple Extras folder, and then open
the AppleScript folder.
d. Double-click Script Editor.
2. On the File Menu, click Open Dictionary.
3. In the Open Dictionary dialog box, select Microsoft Excel
(Application) in the Name list, and then click Open.
In the window that appears, you can select an object or a class to
view its description. You can also click the bold suite names to view
an whole suite at one time. You can use the descriptions in this
window to create scripts in the Script Editor to control Excel for
Mac.
The versions of Excel for Mac listed at the beginning of this article
support a very large number of events. For a complete list, follow the
instructions in this article to open Excel for Mac in the AppleScript
Script Editor.
I don't have access to the Applescript dictionary mentioned above, however, it was ported to Python at some point, and you can view a complete set of commands here.

It's the select command of Microsoft Word. Wrap around a tell "Microsoft Word" block around it and it will be corrected using the application's dictionary.

Related

Concatenate multiple text files in macOS

I would like to concatenate multiple text files with various extensions (.log, .log.1, .log.2, etc.) into a single file called -concatenated..
I have created this Automator service workflow which doesn't work:
failed Automator Service Workflow attempt
It only text text from the first items in my test (first item is a .log file, while the next one is a .1)
I can't figure out how to put the name and extension of the first file selected into a variable.
I am on macOS Big Sur 11.1, in case it is relevant.
It does not have to be automator but I would like something I can do quickly from within finder, either using the contextual menu or using a couple of key strokes (using Alfred for example).

Run Applescript on selected text and store it on clipboard

I'm looking for a solution to be able to select a text on an app(Figma) and then reverse it then store reverse version to the clipboard.
I used BetterTouchBar app for saving selected text but I can't do anything with it.
How can I do that with or without BetterTouchbar App.
Thanks a lot.
Create an Automator Quick Action1, setting Workflow receives current text in any application and add a Run AppleScript action, adding the following line of example AppleScript code where is says: (* Your script goes here *)
set the clipboard to the (reverse of characters of item 1 of input) as text
Save the Quick Action as e.g.: Reverse Selected Text To Clipboard
It's now available from the Services menu in any application, e.g. TextEdit > Services, or the Services menu on the Context menu (right-click menu).
You can also assign a keyboard shortcut in: System Preferences > Keyboard > Shortcuts > Services
1 In versions of macOS prior to Mojave a Quick Action is called a Service.
Note: The example AppleScript code is just that and does not contain any error handling as may be appropriate. The onus is upon the used to add any error handling as may be appropriate, needed or wanted. Have a look at the try statement and error statement in the AppleScript Language Guide. See also, Working with Errors.

Applescript Droplet Text as Input

How can I create a droplet that takes a text selection as input? When I create a script that starts with on run inputText, the resulting application icon will only darken when files are dragged over it.
You can achieve a similar result by using Automator to make a service. Services can be fed selected text, (or urls or files etc) and not just from Finder, but from the right-click contextual menu or the Services menu. You can run applescript inside the Automator script, so basically Automator makes a wrapper for your appleScript. The downside is that it tends to be even slower than applescript.
Dropplets in AppleScript only support files. You can follow #stib's suggestion of using a service with Automator or using the Scripts menu (launch AppleScript Editor and choose AppleScript Editor>Preferences from the menu bar, General in the preferences window and check "Show Script menu in menu bar"). You can then place the script in the /Library/Scripts/ or ~/Library/Scripts folder to have the script appear in the menu. Alternatively, check out FastScripts to include the ability to assign keyboard shortcuts to the scripts and enhanced menu organization.
In applescript, you can create a simple droplet like this:
on open theThing
set fileToRead to open for access theThing --open the file so we can perform operations on it
set myVar to (read fileToRead) --The myVar variable is set to the contents of the dropped file
display dialog myVar --Shows the contents of the file in a dialog; do what you want with the text here
//other code here
close access fileToRead
end open
So, it's not too hard, just make sure you open for access the file first. I hope this helped!
Helpful Links:
http://macscripter.net/viewtopic.php?id=24772: About Droplets
http://macscripter.net/viewtopic.php?id=24745: About File IO
As far as I could tell, this could only be achieved by wrapping the Applescript in a Cocoa application. I don't know Objective-C, but was able to cobble something together. When I get a chance I'll try to clean up a bit and post an explanation.

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.

run applescript on 2x-click

OK, this feels like an idiot question, but I'm stuck - I don't know the first thing about AppleScript. I have a .scpt file and I want to double-click it and just have it run, but instead every time I click, it opens up the AppleScript Editor. This feels like it should just be an option on the file, but I'm missing something obvious.
Please help me feel less dumb, thank you.
From the “File” menu, choose “Export”; there’ll be a “File Format” dropdown underneath the file browser. To get a double-clickable application instead of a document, choose “Application”. This will produce a .app bundle like ordinary Mac applications (this will also let you package other resources with your script if you need to). You can choose “Run Only” or not; if you do, then anybody with just the .app won’t be able to edit your script further, since it’ll be compiled. (But if you’re saving a copy as the application, that might be what you want.)
Another option, as per an anonymous user on Ask Different, would be to save/export your file as a “Script” (.scpt) or “Script Bundle” (.scptd), save it in ~/Library/Scripts/, and check “Show Script menu in menu bar” in Script Editor’s preferences.
(If you’re running an old version of OS X, the first version of this answer has the information you’re looking for.)
There's more than one way to do it; i have found this to be the simplest:
In sum, you create an Automator application and place your applescript inside it (easier than it sounds, and it's not a hack either--there's actually a specific Automator action for this). Then when you are finished, you select "File" from the menubar, next "Save As Application", then select a location. Now check there and you'll see the newly-created Automator icon (little white robot holding a grenade launcher).
You can do anything that you would ordinarily do with this application icon--double click to open, drag it to your dock, etc.
Appstorm has created an excellent step-by-step tutorial for building an applescript-embedded automator action. On the page i linked to, the tutorial author has also supplied an Automator script that you can download and use as a template.
While it's certainly not the simplest route, one benefit to running your script from Automator, as doug suggested, is that you can set a hotkey or keyboard shortcut to execute your script if you hide it in an Automator Service (OSX 10.6+). See:
http://blog.fosketts.net/2010/08/09/assign-keyboard-shortcut-applescript-automator-service/
When you save a new script, a menu should appear asking what you want the file name to be, where it will be stored, any tags for it, and what script format you want it to be. There should be 4 scripts formats:
Script
Script Bundle
Application
Text
The script format you want to use would be "Application." This will turn it into a double-click application if its not in the dock.

Resources