{"id":61,"date":"2013-07-17T09:07:18","date_gmt":"2013-07-17T08:07:18","guid":{"rendered":"https:\/\/desairem.com\/usync\/wordpress\/?p=61"},"modified":"2025-10-03T17:59:35","modified_gmt":"2025-10-03T16:59:35","slug":"synctime-custom-script-before-or-after-a-sync","status":"publish","type":"post","link":"https:\/\/desairem.com\/wordpress\/synctime-custom-script-before-or-after-a-sync\/","title":{"rendered":"Custom script before or after a sync"},"content":{"rendered":"\n<p>For each sync item you can define whether your Mac should send an email, a Slack message, quit SyncTime, go to Sleep, shut down or execute an arbitrary script after the sync has completed. You can also define a script to run before the sync starts. You can find these options in the Advanced tab of the sync item settings.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1324\" height=\"1328\" src=\"https:\/\/desairem.com\/wordpress\/wp-content\/uploads\/2025\/10\/synctime-sync-settings-advanced.png\" alt=\"\" class=\"wp-image-5137\" style=\"width:662px\"\/><\/figure>\n\n\n\n<p>Alternatively, you can define a script that will be executed once after all syncs have completed, either from the status item menu, the File menu or the main window context menu. This general script is executed only once and then reset to the default <em>No custom script<\/em>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1419\" height=\"862\" src=\"https:\/\/desairem.com\/wordpress\/wp-content\/uploads\/2025\/10\/synctime-status-item-menu.png\" alt=\"\" class=\"wp-image-5132\" style=\"width:710px\"\/><\/figure>\n\n\n\n<p><strong>Tip<\/strong>: if you want to execute a script <em>every time<\/em> all syncs have completed, at the beginning of the script you can send a command to set the script again. For additional help, see <a href=\"https:\/\/desairem.com\/wordpress\/synctime-control-synctime-with-applescript\/\" data-type=\"post\" data-id=\"3057\">Control SyncTime with AppleScript<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Install predefined script<\/h2>\n\n\n\n<p>SyncTime offers some predefined scripts that you can automatically install in your user scripts directory. macOS only allows scripts inside this directory to be executed. You can also create your own scripts (see below), or edit the installed scripts.<\/p>\n\n\n\n<p><strong>Note<\/strong>: the predefined scripts are designed to work only when the sync completes, not before the sync starts.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Open the <em>Edit scripts<\/em> window, either from the status item menu or the main window context menu by selecting <em>Once All Syncs Are Completed &gt; Edit Scripts<\/em>.<\/li>\n\n\n\n<li>Click the Download button beside the desired script. You can choose any of the following predefined scripts:\n<ul class=\"wp-block-list\">\n<li>Play sound<\/li>\n\n\n\n<li>Quit SyncTime<\/li>\n\n\n\n<li>Send email<\/li>\n\n\n\n<li>Send Slack message<\/li>\n\n\n\n<li>Shut down<\/li>\n\n\n\n<li>Sleep<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Click Install.<\/li>\n\n\n\n<li>Close the <em>Edit scripts<\/em> window. An item corresponding to the new script&nbsp;is now available throughout the app.<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1224\" height=\"1088\" src=\"https:\/\/desairem.com\/wordpress\/wp-content\/uploads\/2025\/10\/synctime-edit-scripts.png\" alt=\"\" class=\"wp-image-5200\" style=\"width:612px\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Install custom script<\/h2>\n\n\n\n<p>If you cannot find a predefined script that satisfies your needs, you can write your own script.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Open the AppleScript Editor (located in <code>\/Applications\/Utilities<\/code>).<\/li>\n\n\n\n<li>Create a new document. You can start populating it by pasting one of the codes given below.<\/li>\n\n\n\n<li>Save the document on the Desktop with a meaningful name.<\/li>\n\n\n\n<li>Open the <em>Edit scripts<\/em> window in SyncTime, either from the status item menu or the main window context menu by selecting <em><em>Once All Syncs Are Completed &gt; Edit Scripts<\/em><\/em>. Then click on <em>Show Scripts Directory in Finder<\/em>. (The scripts directory is located at <code>\/Users\/yourusername\/Library\/Application Scripts\/org.desairem.uSync<\/code>.) Drag the newly created file into this directory.<\/li>\n\n\n\n<li>Close the <em>Edit Scripts<\/em> window in SyncTime. An item corresponding to the new file\u00a0is now available throughout the app.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Codes<\/h3>\n\n\n\n<p>If you&#8217;re writing a script to run <strong>before a sync starts<\/strong> and want to include some information about the sync, write your code inside a handler with the following signature:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>on syncStart(syncItem)\n    ...\nend syncStart<\/code><\/pre>\n\n\n\n<p>If you&#8217;re writing a script to run <strong>after a sync completes<\/strong> and want to include some information about the sync, write your code inside a handler with the following signature:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>on syncCompleted(syncItem, stateCode, stateLabel, scheduleLabel)\n    ...\nend syncCompleted<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Sleep<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>tell application \"System Events\" to sleep<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Shut down<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>tell application \"System Events\" to shut down<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Play a sound with a given filename<\/h4>\n\n\n\n<p>You may store your custom sounds as well in <code>\/Users\/yourusername\/Library\/Application Scripts\/org.desairem.uSync<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>do shell script \"afplay \/System\/Library\/Sounds\/Glass.aiff\"<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Play a random system sound<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>do shell script \"afplay \/System\/Library\/Sounds\/\" &amp; some item of paragraphs of ((do shell script \"ls \/System\/Library\/Sounds\/\"))<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Quit SyncTime<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>tell application \"SyncTime\" to quit<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>For each sync item you can define whether your Mac should send an email, a Slack message, quit SyncTime, go to Sleep, shut down or execute an arbitrary script after the sync has completed. You can also define a script to run before the sync starts. You can find these options in the Advanced tab [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"wp-custom-template-sync-time-help-post","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-61","post","type-post","status-publish","format-standard","hentry","category-synctime-help"],"_links":{"self":[{"href":"https:\/\/desairem.com\/wordpress\/wp-json\/wp\/v2\/posts\/61","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/desairem.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/desairem.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/desairem.com\/wordpress\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/desairem.com\/wordpress\/wp-json\/wp\/v2\/comments?post=61"}],"version-history":[{"count":65,"href":"https:\/\/desairem.com\/wordpress\/wp-json\/wp\/v2\/posts\/61\/revisions"}],"predecessor-version":[{"id":5212,"href":"https:\/\/desairem.com\/wordpress\/wp-json\/wp\/v2\/posts\/61\/revisions\/5212"}],"wp:attachment":[{"href":"https:\/\/desairem.com\/wordpress\/wp-json\/wp\/v2\/media?parent=61"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/desairem.com\/wordpress\/wp-json\/wp\/v2\/categories?post=61"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/desairem.com\/wordpress\/wp-json\/wp\/v2\/tags?post=61"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}