Full Code of dunckr/sketch-subtlepatterns for AI

master 25d1c3158456 cached
8 files
4.7 KB
1.4k tokens
10 symbols
1 requests
Download .txt
Repository: dunckr/sketch-subtlepatterns
Branch: master
Commit: 25d1c3158456
Files: 8
Total size: 4.7 KB

Directory structure:
gitextract_0q3zx_n8/

├── README.md
├── SubtlePatterns/
│   └── .gitignore
├── lib/
│   └── util.js
├── random.sketchplugin
├── sketchpack.json
├── update.sh
└── vendor/
    ├── README.md
    └── index.js

================================================
FILE CONTENTS
================================================

================================================
FILE: README.md
================================================
# Sketch SubtlePatterns

Import [Subtle Patterns](https://github.com/subtlepatterns/SubtlePatterns) as shape fills in Sketch.

![subtlepatterns](https://raw.githubusercontent.com/dunckr/sketch-subtlepatterns/master/assets/example.png)

## Usage

![Using plugin](https://raw.githubusercontent.com/dunckr/sketch-subtlepatterns/master/assets/usage.gif)

+ Select Shapes
+ Run using ```Plugins > Menu > sketch-subtlepatterns > random```
+ Wait for the images to be inserted as a fill

## Installation

The [official documentation](http://bohemiancoding.com/sketch/support/developer/01-introduction/01.html) explains how to install plugins in detail.

### Clone

+ Find Sketch Plugins folder using ```Plugins menu > Reveal Plugins Folder```
+ e.g. ```git clone /Users/dunc/Library/Containers/com.bohemiancoding.sketch3/Data/Library/Application\ Support/com.bohemiancoding.sketch3/Plugins```

### Download

+ Find Sketch Plugins folder using ```Plugins menu > Reveal Plugins Folder```
+ [Download](https://github.com/dunckr/sketch-subtlepatterns/archive/master.zip)
+ Unzip and copy into the Sketch plugins folder

## Update

```sh
./update.sh
```

## Thanks

A big thanks to the awesome [SubtlePatterns](http://subtlepatterns.com/).

## License

MIT © [Duncan Beaton](http://dunckr.com)


================================================
FILE: SubtlePatterns/.gitignore
================================================

.DS_Store


================================================
FILE: lib/util.js
================================================
@import 'vendor/index.js'

var DATA_PATH = 'SubtlePatterns/';

function getDir(name) {
  var scriptPath = sketch.scriptPath;
  var pluginFolder = scriptPath.match(/Plugins\/([\w -])*/)[0] + '/';
  var sketchPluginsPath = scriptPath.replace(/Plugins([\w \/ -])*.sketchplugin$/, '');
  return sketchPluginsPath + pluginFolder + name;
}

function getFilePath(dir, type) {
  var fileManager = NSFileManager.defaultManager();
  var imagesFileNames = fileManager.contentsOfDirectoryAtPath_error(dir, nil);
  var imgLen = imagesFileNames.count();
  var ran = random(imgLen);
  var fileName = imagesFileNames[ran];
  if (endsWith(fileName, 'png')) {
    return fileName;
  }
  return imagesFileNames[1];
}

function loadImage() {
  var imagesPath = getDir(DATA_PATH);
  var fullPath = imagesPath + getFilePath(imagesPath, '.png')
  return NSImage.alloc().initWithContentsOfFile(fullPath);
}

function setSelection() {
  var loop = selection.objectEnumerator();
  while (layer = loop.nextObject()) {
    var data = loadImage();
    setImage(layer, data);
  }
}


================================================
FILE: random.sketchplugin
================================================
@import 'lib/util.js'

setSelection();


================================================
FILE: sketchpack.json
================================================
{
    "name": "Subtle Patterns",
    "description": "Import subtle patterns as shape fills in Sketch",
    "tags": ["placeholders", "images"]
}

================================================
FILE: update.sh
================================================
#!/bin/bash

rm -rf SubtlePatterns

git clone https://github.com/subtlepatterns/SubtlePatterns

rm SubtlePatterns/{*.zip,*.php,*.html,*.md}


================================================
FILE: vendor/README.md
================================================
# Sketch Utils

Helper functions for creating Sketch plugins.

## Usage

+ Git clone or subtree

```git subtree add --prefix vendor https://github.com/dunckr/sketch-utils master —squash```

+ Import into sketchplugin file

```#import 'vendor/utils.js'```

## License

MIT © [Duncan Beaton](http://dunckr.com)


================================================
FILE: vendor/index.js
================================================
/**
 * AJAX request.
 *
 * @param {String} url
 * @return {NSString}
 */
function request(url) {
  var request = NSURLRequest.requestWithURL(NSURL.URLWithString(url));
  return NSURLConnection.sendSynchronousRequest_returningResponse_error(request, null, null);
}

/**
 * Convert NSString to String.
 *
 * @param {NSString} response
 * @return {String}
 */
function toString(response) {
  return NSString.alloc().initWithData_encoding(response, NSUTF8StringEncoding);
}

/**
 * Fill layer with Image Data
 *
 * @param {Layer} layer
 * @param {Image} image
 * @return {Fill}
 */
function setImage(layer, image) {
  var version = sketchVersion()
  var fill = layer.style().fills().firstObject();
  fill.setFillType(4);
  fill.setPatternFillType(0);
  if (version > 370) {
    var imageData = MSImageData.alloc().initWithImage_convertColorSpace(image, false)
    fill.setImage(imageData)
  } else if (version < 350) {
    fill.setPatternImage_collection(image, fill.documentData().images())
  } else {
    fill.setPatternImage(image)
  }
  fill.setPatternFillType(0);
  return fill;
}

/**
 * Random number between 0 and limit
 *
 * @param {Number} limit
 * @return {Number}
 */
function random(limit) {
  return Math.floor(Math.random() * limit) + 1;
}

/**
 * Determine if Str ends with a suffix
 *
 * @param {String} str
 * @param {String} suffix
 * @return {Boolean}
 */
function endsWith(str, suffix) {
  return str.indexOf(suffix, str.length - suffix.length) !== -1;
}


/**
 * Sketch Version as a number
 *
 * @return {Number}
 */
function sketchVersion() {
  var version = NSBundle.mainBundle().objectForInfoDictionaryKey('CFBundleShortVersionString')
  var versionNumber = version.stringByReplacingOccurrencesOfString_withString('.', '') + ''
  if (versionNumber.length < 3) versionNumber += '0'
  return parseInt(versionNumber)
}
Download .txt
gitextract_0q3zx_n8/

├── README.md
├── SubtlePatterns/
│   └── .gitignore
├── lib/
│   └── util.js
├── random.sketchplugin
├── sketchpack.json
├── update.sh
└── vendor/
    ├── README.md
    └── index.js
Download .txt
SYMBOL INDEX (10 symbols across 2 files)

FILE: lib/util.js
  function getDir (line 5) | function getDir(name) {
  function getFilePath (line 12) | function getFilePath(dir, type) {
  function loadImage (line 24) | function loadImage() {
  function setSelection (line 30) | function setSelection() {

FILE: vendor/index.js
  function request (line 7) | function request(url) {
  function toString (line 18) | function toString(response) {
  function setImage (line 29) | function setImage(layer, image) {
  function random (line 52) | function random(limit) {
  function endsWith (line 63) | function endsWith(str, suffix) {
  function sketchVersion (line 73) | function sketchVersion() {
Condensed preview — 8 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (5K chars).
[
  {
    "path": "README.md",
    "chars": 1282,
    "preview": "# Sketch SubtlePatterns\n\nImport [Subtle Patterns](https://github.com/subtlepatterns/SubtlePatterns) as shape fills in Sk"
  },
  {
    "path": "SubtlePatterns/.gitignore",
    "chars": 11,
    "preview": "\n.DS_Store\n"
  },
  {
    "path": "lib/util.js",
    "chars": 1052,
    "preview": "@import 'vendor/index.js'\n\nvar DATA_PATH = 'SubtlePatterns/';\n\nfunction getDir(name) {\n  var scriptPath = sketch.scriptP"
  },
  {
    "path": "random.sketchplugin",
    "chars": 39,
    "preview": "@import 'lib/util.js'\n\nsetSelection();\n"
  },
  {
    "path": "sketchpack.json",
    "chars": 143,
    "preview": "{\n    \"name\": \"Subtle Patterns\",\n    \"description\": \"Import subtle patterns as shape fills in Sketch\",\n    \"tags\": [\"pla"
  },
  {
    "path": "update.sh",
    "chars": 140,
    "preview": "#!/bin/bash\n\nrm -rf SubtlePatterns\n\ngit clone https://github.com/subtlepatterns/SubtlePatterns\n\nrm SubtlePatterns/{*.zip"
  },
  {
    "path": "vendor/README.md",
    "chars": 309,
    "preview": "# Sketch Utils\n\nHelper functions for creating Sketch plugins.\n\n## Usage\n\n+ Git clone or subtree\n\n```git subtree add --pr"
  },
  {
    "path": "vendor/index.js",
    "chars": 1837,
    "preview": "/**\n * AJAX request.\n *\n * @param {String} url\n * @return {NSString}\n */\nfunction request(url) {\n  var request = NSURLRe"
  }
]

About this extraction

This page contains the full source code of the dunckr/sketch-subtlepatterns GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 8 files (4.7 KB), approximately 1.4k tokens, and a symbol index with 10 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!