Code Monkey home page Code Monkey logo

vscode-applescript's Introduction

AppleScript for Visual Studio Code

Version Visual Studio Marketplace Installs Open VSX Downloads Build

Language syntax, snippets and build system for AppleScript and JavaScript for Automation

Screenshot

Screenshot of AppleScript in Visual Studio Code with Hopscotch theme

Installation

Extension Marketplace

Launch Quick Open, paste the following command, and press Enter

ext install idleberg.applescript

CLI

With shell commands installed, you can use the following command to install the extension:

$ code --install-extension idleberg.applescript

Packaged Extension

Download the packaged extension from the the release page and install it from the command-line:

$ code --install-extension path/to/applescript-*.vsix

Alternatively, you can download the packaged extension from the Open VSX Registry or install it using the ovsx command-line tool:

$ ovsx get idleberg.applescript

Usage

Building

On macOS, you can make use of the following build commands through the command-palette:

  • AppleScript: Run Script – Shift ⇧+Option ⌥+R
  • AppleScript: Compile Script – Shift ⇧+Option ⌥+B
  • AppleScript: Compile Script bundle
  • AppleScript: Compile Application
  • JXA: Run Script
  • JXA: Compile Script
  • JXA: Compile Script bundle
  • JXA: Compile Application

Settings

You can tweak the defaults for this package, osacompile and osascript in the package settings.

Setting Default Description
showNotifications true Show build notifications indicating success or failure
alwaysShowOutput false Specify whether to show the output panel on errors only or on each build
convertErrorRange false Convert error range to line/column
defaultBuildTask "script" Specify the default build task when creating a new task file
allowMultiTermination false Allows the selection of multiple processes to be terminated
osacompile.executeOnly false Save the resulting script as execute-only
osacompile.stayOpen false Stay open after run handler
osacompile.startupScreen false Show startup-screen
osascript.outputStyle - The flags argument is a string consisting of any of the modifier characters e, h, o, and s
scpt.theme "(none)" Custom syntax theme for binary AppleScript files, which are opened in a custom web-view
scpt.overrideThemeBackground false Allows overriding the syntax-theme's background color

File Encoding

The default character encoding for AppleScript text files is Mac Roman. If you wish to change this, you can do so in the settings.

Example:

{
  "[applescript]": {
    "files.encoding": "utf16le"
  }
}

License

This work is licensed under The MIT License

vscode-applescript's People

Contributors

idleberg avatar dependabot[bot] avatar rodya avatar

Stargazers

 avatar  avatar Umar Hansa avatar Nuclear Pasta avatar 简简 avatar Vincent avatar Roberto avatar Jakub Sarnowski avatar Shinji Kuriyama avatar Kayvan Sylvan avatar Alessio Treglia avatar yuriever avatar seeumara avatar Arthur Pinheiro avatar dennishoyer avatar  avatar Jacob Arnould avatar Finn avatar vancaem avatar Cody Henderson avatar Johnnie Wilcox avatar Adam Oswald avatar  avatar David Brockmeier avatar Shunyuan Mao avatar Sasaki “se7en” Atsushi avatar Tobias Zittlau avatar Arbal avatar Rik Hoffbauer avatar Hiroyuki Nobe avatar zacks avatar Mark Auger avatar  avatar Phisch avatar Bob avatar Peng.xn avatar Doug Franklin avatar Ed Mechem avatar  avatar  avatar Fayaz Ahmed avatar César Román avatar Chalita N Washington avatar Daniel Bayley avatar  avatar Nikita avatar CK avatar Dave Torres avatar Dennis Muensterer avatar  avatar Cody Gagnon avatar Mo avatar John Burwell avatar Yanbo Wong avatar  avatar Adán G. Galván González avatar Victor avatar Michael Berger avatar Ouwéis avatar Nicolas Furno avatar Christin White avatar John Elm avatar Makoto Shimabukuro avatar akabeko avatar azu avatar JMichaelTX avatar Thomas Kobert avatar Anson Chen avatar Dalton Jorge avatar

Watchers

Ed Mechem avatar James Cloos avatar  avatar  avatar  avatar Stan Waring avatar

vscode-applescript's Issues

Syntax highlighting for Markdown Fenced Code

I was hoping that this extension would syntax-highlight code in Markdown fenced code in .md files, e.g.:

tell application "Finder" to get the name of front Finder window

but it doesn't seem to. Is this something it can support? Are there changes to settings.json that I need to make to enable this?

(btw I notice that AppleScript is syntax-highlighted here in GitHub!)

Debugging JXA?

I kind of want to resurrect this "issue" : #6 . It's been three years since that question was asked, and a lot can change in that time.

Here's JXA as I understand it, more or less:

Of course there's the issue that both AppleScript scripts and JXA scripts are typically .scpt or .scptd -- binary files -- that VSCode doesn't open in any particularly useful way. So a reasonable workflow for AS and JXA seems to be do the coding in text files and then compile them to .scpt/d files to run them.

As noted by MichaelTX in that issue the Mac has built in debugging for JXA using the Safari browser debugger, which is... ok... but not great.

I've just posted another issue asking about AppleScript debugging, and I have the same request here. I'm looking/hoping for an experience that's similar to VSCode's built in Node debugging but with JXA scripts.

I have no idea what's involved in building a debugger. I imagine it's a lot of work. I think whoever wrote VSCode's node debugging has done a great job. I'd love to see something that has a very consistent experience for JXA (and AppleScript) also.

Is this somehow already in this AS plugin and I'm not seeing it? I'm guessing not, and if so, what would it take to add it?

Thanks!

Open and save script files

Summary

Ability to open script files with extension (*.scpt, *.scptd, *.app, *.sdef)

Motivation

Currently, we can't open script files or applescript apps and their script definition dictionary

Describe alternatives you've considered

I've build a script to open scripts as simple text files

Just use simply "osadecompile /path/to/file.scpt > path/to/test.txt | open -a VsCode path/to/test.txt"

You could implement this code in your plugin, because my script is just a temporary solution

Additional context

Furthermore, I'd like to save my applescript inside vscode, osacompile should be able to save code as script files and script files embedded into applescript apps (*.scpt, *.scptd, *.app)

Of course, apps need also a xml plist, a script runner, some icon and their folder structure. Maybe you're willing to put app creation on your Roadmap for later?

Compile a run-only script or app ?

The Script Editor app has an option to export a run-only script or app. When used, the script can only be runned, the source can not be read or modified.

capture d ecran 2018-08-08 a 18 23 37

If it is possible, could we have a similar option when compiling a script from Visual Studio Code ?

Can you use VSC Debugging with JXA Files?

Can you use VSC Debugging with JXA Files?

In Script Editor, this requires an elaborate, unreliable setup using Safari Debugger.
If we can use VSC, could you please provide detailed steps to do so.

Thanks.

Could we have full logs when running ?

I'm not sure it's technically possible, but if it is, it would be really nice to have a full log when running a script.

What I mean by full log, is what the Script Editor.app made by Apple can display when you run a script. For instance, with this script, here's what the Apple app gives me when I run :

tell application "Safari"
	activate
end tell
tell application "System Events"
	get name of process 1 whose frontmost = true
end tell
tell application "Safari"
	get URL of current tab of window 1
end tell
tell current application
	do shell script "echo 'https://voiretmanger.fr/wp-content/uploads/2017/08/handmaids-tale-saison-2-700x467.jpg' | grep -o '\\-[0-9]\\+x[0-9]\\+'"
	do shell script "echo 'https://voiretmanger.fr/wp-content/uploads/2017/08/handmaids-tale-saison-2-700x467.jpg' | grep -o '\\-[0-9]\\+x[0-9]\\+'"
	do shell script "curl -s -L -o /dev/null -I -w \"%{http_code}\" 'https://voiretmanger.fr/wp-content/uploads/2017/08/handmaids-tale-saison-2.jpg'"
	(*https://voiretmanger.fr/wp-content/uploads/2017/08/handmaids-tale-saison-2.jpg*)
end tell
tell application "Safari"
	close current tab of window 1
	open location "https://voiretmanger.fr/wp-content/uploads/2017/08/handmaids-tale-saison-2.jpg"
end tell

In contrast, here's what Visual Studio Code gives me, the only log in the script :

[Running] osascript "/Users/nicolas/Git/perso/full-images/full-images.applescript"
https://voiretmanger.fr/wp-content/uploads/2017/08/handmaids-tale-saison-2.jpg

[Done] exited with code=0 in 0.601 seconds

The full log is far more useful to see what happens and debugs the script. In many case, the log commands are not even necessary, while I have to use it constantly with VSCode.

So, again, if possible, would be great.

Anyway, thanks for your work on this extension ! 👍

Go to symbol for AppleScript ?

One feature missing in Visual Studio Code for AppleScript files is the ability to go to a symbol. It would be useful to have this feature to navigate in long scripts, from a function to the next or to jump to a specific function in the file.

I don't know if it is possible, but if that's the case, it would be a welcome addition I think.

Javascript support

Support Javascript language for scripting. I think this would just be slight modifications to calling the compiler and runner processes and possibly adding "Javascript Applescript" as a new language?

command not found

After installing this extension, I can't run any of the commands. I get this error message.
command 'extension.applescript.compile' not found

I get the same error message for all four of the commands.

How do you stop a script after starting it? 😂

Amazing extension wow, a little more documentation about how it works and runs would be amazing?!

And if it's possible to view log outputs??

But yes, do you know how to stop a script besides through activity monitor? 😂

Thank you so much 🙏

Does This Extension Fully Support JavaScript Code Completion in JXA file?

I'm getting mixed results trying to answer that question.

I have one file where it auto-completes for the "repeat" function, but it does not in another file.
I just figured it out. If offers auto-complete if that function had been previously used.

So, it appears that real, full JavaScript code completion is not supported.
Is there some way, with some other extension or setting, we can get this?
JavaScript code completion is the main reason I use VSC for coding JavaScript, and JXA.

Line number on error message

First of all thanks for this great extension, it is truly another way to manage Applescripts :-D
When it is running or compiling the code and it is encountered an error, is it possible to have the line number of the wrong part of the code?
Thank you so much in advance.

Can't open .scpt files

Now the extension can only open applescripts which format is .applescrit, but can't open and edit .scpt file.

Debugging AppleScript?

Is there any way this plugin does, or can, do AppleScript debugging (perhaps similar to Late Night Software's Script Debugger)?

Two things here:

  1. I can't seem to find any way that it does it already, but want to check I'm not missing anything.
  2. If that's right and it doesn't currently do it, what would it take to get it to do it?

To really clarify, in case there's any ambiguity: I'm looking/hoping for an experience that's similar to VSCode's built in Node debugging (but with AppleScript of course).

If it's not already possible, I imagine it's a lot of work, but... I'll bet I'm not the only one who would really like this.

Does this somehow do this already and I'm missing it? Or if not, is it possible to add this?

Thanks!

Disable Toolbar buttons

Hello,
is it possible to disable the buttons added by the extension? Or at least to enable them only for apple script extensions? I have no interest in using them when I'm editing a js or py file.
image

Support osascript shebang

Summary

A file with no extension, but with an osascript shebang, should be highlighted as AppleScript:

#!/usr/bin/env osascript

tell application "Terminal"
  do script ""
end tell

Motivation

I have a ./dev script that I don't want to add a .applescript extension to.

Describe alternatives you've considered

Additional context

Problem running scripts

Hello,

I am just learning AppleScript and trying to run the following simple script:
tell application "Finder" to get the index of Finder window "Macintosh HD"

It runs fine in ScriptEditor giving me the answer: 1

The first time I ran it in VSCode with this extension, it worked. But now I get the following error in the results window:
osascript: extension-output-idleberg.applescript-#1-AppleScript: No such file or directory

Whatever script I run, I get this error. The scripts compile fine, but I can never run them.

I am using all the default options except the option to always show the results.

I have tried reinstalling the extension, restarting VSCode and recreating the files with the script, but none of those worked.

As I say, I am completely new to AppleScript, so maybe there is something obvious I am doing wrong, but I can't figure it out.

Support unsaved files

If I open a new editor, and set the language mode to AppleScript I'm still not able to run the script until I save the actual file to the disk.

It would be great if this extension fully supported unsaved editors.

Stop a script

This extension is great, thank you for writing it. The one thing I wish it had was a Stop Script button like Apple's script editor. I was doing repeat until and sometimes things would hang up. A trip to the Activity Monitor allowed me to kill the wayward process but a stop button would have been a welcome convenience. It would also be nice to have indentation formatting support but I get the feeling that is probably a much bigger deal.

Change default encoding to MacRoman

Script Editor saves .applescript text scripts in the MacRoman encoding. It's similar enough to some other encodings that it can't be auto-detected from the content itself. Example:

  1. In VSCode settings, turn on files.autoGuessEncoding.
  2. Save the script x ≥ 1 as MacRoman.
    (You can either use Script Editor or VSCode.)
    Close the file after saving.
  3. Open the file in VSCode. It thinks the content is "Windows 1252"-encoded, and it thinks the content is x ³ 1.

Adding this in my VSCode settings informs VSCode of the proper encoding for AppleScript files:

    "[applescript]": {
        "files.encoding": "macroman",
    },

It would be nice if this package did this automatically!

Questions:

  • Would it be possible to add a "Save AppleScript files as MacRoman" setting?
  • Would it be a good idea for this setting to be enabled by default?

command not found

(Read the previous 'command not found issue', still isn't working)
I get this error: command 'extension.applescript.compile' not found when I am trying to compile my script, not sure why. Any ideas?

AutoComplete feature does not work

I wanted to input 'activate' using autocomplete But it does not work
When I started the second snippet before the first snippet is complete, the AutoComplete feature does not work

2019-12-04 08-58-57_2

Error: command 'extension.jxa.run' not found

I have v0.16.0 installed. I installed it via VSCode's Extensions tab/sidebar. Obviously I'm running on a Mac.

image

When I use the command "JXA: Run Script", I get this error:

command 'extension.jxa.run' not found

Any ideas? Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.