Help Guide | API Documentation

API (30)

Notes

Sandbox

Some APIs are not Sandbox friendly for the moment, so you'll have to test your applications with Sandbox disabled. For example for all around files manipulation (read, write, delete, ...), the Sandbox requires that the user gives permissions to read/write the specified file. Otherwise you can manipulate files in application Sandbox directory. The path looks like that :
/Users/[username]/Library/Containers/[bundle identifier]/Data

Spaces in strings

If long strings like path or filename contains spaces, you have to include a backslash before the space. Example here.

Line breaks

To add or to catch a line break in a string, use \n (backslash + n), without space after. Example here.

New window

For the moment, opening a new window is not possible via APIs. So if you have to display content in another part of your application, I suggest you to take a look at this light and beautiful jQuery/CSS modal popup : Avgrund by Hakim El Hattab.

↑ Go up

Exit application

Quit the application. If confirmation prompt has been enabled, the user will have to confirm before exit.

Usage (JS)

Stz.quitApp_();

↑ Go up

Minimize application

Miniaturize the window in Dock with system animation effect.

Usage (JS)

Stz.minimizeWindow_();

↑ Go up

Maximize application

Toggle window between the full width/height and the previous size.

Usage (JS)

Stz.maximizeWindow_();

↑ Go up

Toggle fullscreen

Toggle window between the fullscreen mode and the previous size.

Usage (JS)

Stz.fullscreenWindow_();

↑ Go up

Close window

Close the current window. If "Quit application at window close" is enabled, this function will quit the application (with confirmation prompt if enabled).

Usage (JS)

Stz.closeWindow_();

↑ Go up

Change window title

Force to change the window title.

Usage (JS)

Stz.changeTitle_('I love Paris Hilton');

↑ Go up

Change window size

Resize and put the window in screen center (with smooth animations). Width and Height are in pixels.

Usage (JS)

Stz.resizeWindow_({width:400, height:200});

↑ Go up

Change window position

Move the window to a new position. X and Y are in pixels, from top left corner of the screen.

Usage (JS)

Stz.moveWindow_({x:100, y:200});

↑ Go up

Print current page

Open the default print settings window to print the current page.

Usage (JS)

Stz.printPage_();

↑ Go up

Custom message dialog

Open a simple message box with OK button. Can replace basic JavaScript Alert.

Usage (JS)

Stz.messageBox_({title:'Hello World', message:'I am a simple message box.'});

↑ Go up

Copy a string to clipboard

Copy a string to clipboard easily. Can replace a Flash function.

Usage (JS)

Stz.copyStrToClipboard_('Now, I am in your clipboard !');

↑ Go up

Use notification center

Create a real and native notification alert. Your application will be added to Notifications Settings system window for choosing what kind of notifications you want (alert, banners, none).

Usage (JS)

Stz.notifyMe_({title:'Hello', subtitle:'Email', content:'You have a message !'});

↑ Go up

System beep

Play a basic system beep.

Usage (JS)

Stz.beepMe_();

↑ Go up

Launch an application

Launch an application from his name in Applications directory (without arguments).

Usage (JS)

Stz.openApp_('Terminal');
Stz.openApp_('Adobe Photoshop CS6');

↑ Go up

Open URL in default browser

Force to open an URL in the user default internet browser, rather than current window.

Usage (JS)

Stz.openURL_('http://www.parishilton.com');

↑ Go up

Read the content of file

Open and read the content of a file. Only text-type files are supported (txt, xml, html, css, ...).

Usage (JS)

Stz.openTextFile_('/Users/ChuckNorris/Documents/File.txt');
alert(Stz.openTextFile_('/Users/ChuckNorris/Docucments/File.txt'));

↑ Go up

Create and write in a file

Create a file and write strings datas in. If the file already exists, it will be rewritting.
The result will be a boolean in future.

Usage (JS)

Stz.writeStringsToFile_({path:'/Users/ChuckNorris/Documents/', filename:'My File.txt', content:'Hello world'});

↑ Go up

Add strings to file

Add strings to an existing file. File targeted must exists. Use \n to add a line break.

Usage (JS)

Stz.addStringsToFile_({path:'/Users/ChuckNorris/Documents/', filename:'My File.txt', content:'Hello world \nA second line'});

↑ Go up

Create a new directory

Create all directories necessary to build the path you specified. Do not add a slash at the end.
The result will be a boolean in future.

Usage (JS)

Stz.newDirectory_('/Users/ChuckNorris/Desktop/One/Two/Three');

↑ Go up

Delete an item (file/folder)

Delete a single file or a folder and his content. Warning, the deletion is irreversible.
The result will be a boolean in future.

Usage (JS)

Stz.deleteItem_('/Users/ChuckNorris/Desktop/Beurk.txt'));

↑ Go up

Move an item (file/folder) to trash

Move a single file or a folder and his content to user Trash. User can recover the file/folder.
The result will be a boolean in future.

Usage (JS)

Stz.moveToTrash_('/Users/ChuckNorris/Desktop/My\ File.zip');

↑ Go up

Copy an item (file/folder) from-to

Copy a single file or a folder from a location to another one.
The result will be a boolean in future.

Usage (JS)

Stz.copyItem_({from:'/Users/ChuckNorris/Documents/File.txt', to:'/Users/ChuckNorris/Desktop/File.zip'});

↑ Go up

Check if a file is accessible

Check if you can access a file, through Sandbox for example. The result is a Boolean.

Usage (JS)

if (Stz.fileAccessible_('/Users/ChuckNorris/Documents/File.txt') == true) {
		alert('Accessible');
	} else {
		alert('Not accessible');
	}

↑ Go up

Execute a Terminal command

Launch a command line in Terminal. Use three spaces to separate arguments.
Warning : Be careful with this function ! Also I can not guarantee that Apple will love usage of this.

Usage (JS)

Stz.executeShellCmd_({ path:'/usr/bin/open', command:'-e   /Users/ChuckNorris/Desktop/File.rtf' });

↑ Go up

Execute a Shell script

Launch the execution of a Shell script. Extenstion must be .sh or .command.
Warning : Be careful with this function ! Also I can not guarantee that Apple will love usage of this.

Usage (JS)

Stz.openShellScript_('path/to/script.sh');

↑ Go up

Get path to the main bundle application

Get the path to the main bundle application as string.

Usage (JS)

Stz.pathBundle_();
alert(Stz.pathBundle_());

↑ Go up

Get path to the Resources directory

Get the path to the Resources directory in the main bundle application as string.

Usage (JS)

Stz.pathResources_();
alert(Stz.pathResources_());

↑ Go up

Get path to the Documents directory

Get the path to the current user Documents as string.

Usage (JS)

Stz.pathDocuments_();
alert(Stz.pathDocuments_());

↑ Go up

Get path to the Desktop

Get the path to the current user Desktop as string.

Usage (JS)

Stz.pathDesktop_();
alert(Stz.pathDesktop_());

↑ Go up

Get user system language

Get the system language of the current user. Result is a string, two letters (fr, en, de, ...).

Usage (JS)

alert(Stz.sysLang_());

↑ Go up

Play external audio file (issue)

Should play WAV, AIFF and MP3 files, but some issues appears.

Usage (JS)

Stz.playExternalSound_('/Users/BarackObama/Documents/Sound.wav');

↑ Go up

HTML5 geolocation (issue)

Function not recognized...

Usage (JS)

None

↑ Go up

Proceed a GET procedure (issue)

Proceed a GET procedure and catch target content as string. For the moment I have an issue with this API, so you can use a jQuery replacement with XMLHttpRequest.

jQuery replacement

$(document).ready(function () {
		var client = new XMLHttpRequest();
		client.open('GET', 'http://www.sentenzadesktop.com');
		client.onreadystatechange = function () {
			if (client.readyState == 4) {
				Stz.copyStrToClipboard_(client.responseText);
			}
		}
		client.send();
	});

↑ Go up

Zip an item (file/folder) (future)

This API will allow you to compress a single file or a folder and his content as ZIP file. Crypted archives with password will be supported.
The result will be a boolean in future.

Usage (JS)

None

↑ Go up

Unzip an item (file/folder) (future)

This API will allow you to uncompress a ZIP file. Crypted archives with password will be supported.
The result will be a boolean in future.

Usage (JS)

None

↑ Go up

Execute open file dialog (future)

Execute an Open dialog and select a file. The selected path will be given as string. This API should be Sandbox compliant...

Usage (JS)

None

↑ Go up

Execute save file dialog (future)

Execute a Save dialog. The selected path will be given as string. This API should be Sandbox compliant...

Usage (JS)

None

↑ Go up