Questions tagged [cocoascript]

JavaScript for OS X Applications, also known as JXA.

Use this tag with questions about writing JavaScript to control Mac OS X applications. Its sister tag is [applescript] for AppleScript.

Do not use this tag for questions about using "Cocoa Scripting" framework. Use the tag [cocoa-scripting] for that.

19 questions
3
votes
1 answer

How to correctly combine "dot notation" and "braces notation" in cocoascript (sketch)?

In sketch documentation it's stated that dot and braces notations can be mixed with each other. It's even an example available: [[context.document currentPage] deselectAllLayers]; Unfortunately, this code doesn't work in sketch and produce error if…
grigoryvp
  • 40,413
  • 64
  • 174
  • 277
2
votes
2 answers

How to get a checkbox input in a Sketch plugin with Cocoascript?

I have a Sketch plugin that generates three different files based on the user's selection within an artboard. I want to allow the user to select which of the three files they actually want to have generated via checkboxes (instead of always…
Phil Sinatra
  • 419
  • 3
  • 11
2
votes
1 answer

How to convert this CocoaScript “braces notation” to JavaScript “dot notation” (sketch)?

How to convert these CocoaScript “braces notation” to JavaScript “dot notation” syntax? [fileManager createDirectoryAtPath: tmpFolder withIntermediateDirectories: true attributes: nil error: nil]; and [doc saveArtboardOrSlice: artboard toFile:…
Sakari Niittymaa
  • 403
  • 1
  • 3
  • 12
2
votes
1 answer

RGB values from NSColor

I'm attempting to read an osx colorlist (.clr), and having trouble interpreting the values of colors. context: I'm writing a color palette plugin for a design program called Sketch. The plugins are written in cocoascript, which is a bridge between…
2
votes
0 answers

Cocoa script Multithreading

I need to run a long running loop in a background thread, and update the UI once a while on the main thread. How would I be able to do this with Cocoa script ? I am trying to create a Sketch plugin. Thank you.
js123
  • 96
  • 2
  • 8
1
vote
0 answers

Sketch Plugin: How to dynamically update NSButton components (Objective-C, Cocoascript)

I am trying to develop a UI to get input for my sketch plugin. As far as I understand, Sketch allows us to write in JS, Cocoascript and Objective-C and eventually converts everything to Objective-C. I am using the following code to generate the UI…
1
vote
0 answers

Change font new text

Is there a way to assign a specific font to a text in sketch Plugin? I need to create a text and assign it directly the Arial font. Here's my code: var list = [[[NSFontManager sharedFontManager] availableFontFamilies] description]; var layer =…
1
vote
2 answers

Sketch Plugin - NSFileManager contentsOfDirectoryAtPath - not a function

I'm trying to make a plugin for Sketch that allows me to automate the production of multilingual assets. Right now, I select a list of languages files that kick off the process. I use NSOpen Panel to select these. For each language file, it makes a…
Ratedg
  • 11
  • 3
1
vote
1 answer

Sketch Plugin: How to programmatically make a layer exportable?

So, in Sketch, you can mark a layer/group as exportable. And then the layer/group can be exported as .png/.svg/.pdf etc. I was trying to make a Sketch Plugin recently, where I need to mark a layer/group as exportable from code. A layer in code is…
Munim
  • 2,626
  • 1
  • 19
  • 28
1
vote
1 answer

Set a background image for NSWindow using Cocoascript

I'm trying to create a window in this style: I have the following code, but I just get a back background. I guess it can't find the image. var win = [[NSWindow alloc] init] [win setFrame:NSMakeRect(0, 0, 320, 200) display:false] [win…
ed209
  • 11,075
  • 19
  • 66
  • 82
0
votes
1 answer

How can I change the document color space to P3 in Sketch?

I'm trying to create a plugin for Sketch, and I'd like to know how to change the color space of a Sketch document file to P3. Can anyone help? var onRun = function(context) { var doc = context.document; doc.changeColorSpace(ColorSpace.P3,…
0
votes
1 answer

Copy folder to a non-empty directory

Is it possible to copy a folder to a non empty destination without deleting the contents of the destination folder first? My current implementation is as follows var folderObject =…
Vardaan
  • 47
  • 1
  • 7
0
votes
2 answers

How to write to standard data out using JavaScript or AppleScript multiple times?

If I create an AppleScript script called myscript.js and pass it to oascript it will execute the run function once and write "hello world" to standard data out: function run(args) { for (var i=0;i<10;i++) { // out("number " + i); //…
1.21 gigawatts
  • 16,517
  • 32
  • 123
  • 231
0
votes
1 answer

NSXMLElements breaking line before close TAG - Cocoascript

I'm creating an XML file. What I need is to have a line-break before close the TAG My expected printout is instead, the output I have is the following:
icona
  • 1
  • 2
0
votes
1 answer

Sketch Plugin Develop : Is there an API for Sketch to unlock the size of MSBitmapLayer?

The unlock size button in Sketh App I can click this button to unlock the size of a layer in Sketch App. And then I can change the width/height ratio of the image. But I want my Sketch plugin to do this job instead of using my hand to click the…
July
  • 3
  • 2
1
2