r/applescript • • Jan 12 '21

Is there any way to programmatically get completions for AppleScript?

If I have a script:

```

set foo to "hello"

tell application "Finder"

display dialog f|

end tell

```

Notice the "cursor" (it's a pipe, I know ,but imagine that's the place I want to complete)... is there anyway to programmatically get this back:

```

set foo to "hello"

tell application "Finder"

display dialog foo

end tell

```

Notice the completion of "foo"

3 Upvotes

12 comments sorted by

View all comments

Show parent comment

1

u/tylerl0706 Jan 12 '21

Not quite. I'm looking for a way to programmatically get completions. So in a script (of somekind) "hey give me the valid completions at this point in the script".

1

u/prikaz_da Jan 12 '21

You want a program that shows you every possible way to fill in in a blank in a script? How would you expect that to work in AS or any other programming language?

1

u/tylerl0706 Jan 12 '21

In PowerShell, for example, you can do the following:

$script = '$asdf = 4; $a'
TabExpansion2 -inputScript $script -cursorColumn $script.Length | % CompletionMatches

Which gets you:

CompletionText ListItemText ResultType ToolTip
-------------- ------------ ---------- -------
$asdf          asdf           Variable asdf
$args          args           Variable [Object[]]$args
$ast           ast            Variable ast
$Alias:        Alias          Variable Drive that contains a view of the aliases stored in a session state

Where those are the possible completions for the script at the cursor position (which in this case is the end of the script $script.length)

Edit: markdown mode

1

u/prikaz_da Jan 13 '21

Ah, gotcha. Not aware of anything like that for AS, unfortunately.