New AppleScript projects


(Shane Stanley) #41

FYI, SetFile is deprecated. According to the man page:

Tools supporting Carbon development, including /usr/bin/SetFile, were deprecated with Xcode 6.

But it’s not hard with AppleScript, especially if you’re running 10.11 or later:

use AppleScript version "2.5" -- El Capitan or later
use framework "Foundation"
use scripting additions

tell application "Finder"
	set theSelection to selection as alias list
end tell
repeat with aFile in theSelection
	set theURL to (current application's |NSURL|'s fileURLWithPath:(POSIX path of aFile))
	(theURL's setResourceValue:(current date) forKey:(current application's NSURLContentModificationDateKey) |error|:(missing value))
end repeat

Use NSURLCreationDateKey instead for creation date.

(Ed Stockly) #42

Version was promising but I’m finding that it doesn’t work on files on a network volume or on Dropbox files. It can read the version but not set the version on those files.

(Ed Stockly) #43

Most of the client macs are running 10.10. :frowning:

(Shane Stanley) #44

I’m not following. Shouldn’t you be doing that in Script Debugger when you edit them?

(Shane Stanley) #45

You just need an AS-to-NS date handler. Here’s one:

on makeNSDateFrom:theASDate
	set {theYear, theMonth, theDay, theSeconds} to theASDate's {year, month, day, time}
	set theCalendar to current application's NSCalendar's currentCalendar()
	set newDate to theCalendar's dateWithEra:1 |year|:theYear |month|:(theMonth as integer) |day|:theDay hour:0 minute:0 |second|:theSeconds nanosecond:0
	log (newDate's |description|() as text)
	return newDate
end makeNSDateFrom:

(Ed Stockly) #46

I started with three options: Version; creation date; sync master file.

But I’ve narrowed it down to manipulating the creation date.

For version, 99.9% of the time I will be editing in SD, but here may be a few occasions when I go to a client machine that doesn’t have SD and edit the script there and want that version to be shared. But that’s so rare that a workaround should be pretty easy.

The problem is that I have hundreds of scripts that don’t have a version. To make that work I’d have to open each one in SD and add a version. (I’m not sure I can even script that, not much in the SD dictionary or help files about version.) Plus there will be times when I’m syncing files that are not Script Files. (The data files used for text replacements, for example)

Using a masterFile became overly complicated, but it would have given me the option to select which files to sync.

The script that changes the creation date also changes the modification date. It’s probably not a good idea to have modification dates prior to creation dates.

(I found out that the handler Shane provided does not change the creation dates on alias files, but that’s just as well because local aliases on one machine may not be valid on another, so I don’t sync alias files anyway).

(Shane Stanley) #47

It’s the marketing version property.

(Ed Stockly) #48

So marketing version in SD = version in Finder?

I seem to remember seeing an option to automatically increment the version # each time you save a new copy, but I can’t find that in the preferences. Is that somewhere else? And is it available for all scripts or just apps?

(Shane Stanley) #49

Yes. It’s the value for CFBundleShortVersionString in the bundle’s Info.plist file.

It’s in the Resources pane. But that increments the build number (CFBundleVersion in the Info.plist file), not the version number that shows in the Finder.

Because they’re stored in an Info.plist file, they’re limited to bundled scripts (.app and .scptd). So you only see the option in bundled scripts.

Given your environment, I’m surprised you’re not codesigning all your scripts – which would effectively require you to use bundles anyhow.

(Ed Stockly) #50

What is it about my environment that would suggest the extra headache code signing would cause would be helpful?

(Shane Stanley) #51

I’m assuming the fact you’re not approved to run later than 10.10.4 means you’re operating in an otherwise relatively controlled environment.

(Ed Stockly) #52

You would think so, but no, not so much. We’re not able to run beyond 10.10. 4 because the people who certify systems haven’t responded in years. For all I know they’re not even with the company any more.



Here is a script that will allow you to set your script versions to whatever you want. It changes the script and the changes will appear in Finder.

The version is set by changing the marketing version of the document. The trick is to do a save after changing it or the change won’t appear in Finder. This script automatically saves the changes and closes the script window after it is done. The file included with this post has 10 .scptd files with no version set yet. You can run the script to see them change right in Finder. The script changes all files selected in Finder, but you can change the way it selectes files to something else. It a pretty small straight forward script.

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

on SaveDocument(TheDocument)
	-- Saves without a dialog appearing
	tell application "Script Debugger"
		set TheDocumentPath to (file spec of TheDocument)
		save TheDocument in TheDocumentPath
	end tell
end SaveDocument

tell application "Finder"
	set SelectedFiles to selection
	repeat with TheFile in SelectedFiles
		tell application "Script Debugger"
			set TheDocument to open file (TheFile as string)
			set marketing version of TheDocument to "1"
			my SaveDocument(TheDocument)
			close TheDocument saving no
		end tell
	end repeat
end tell

Added 11/27/16:
I included some sample scripts (Make all versions with no version number entered for the script files that you can use to test this script.

Make all versions (71.9 KB)



For the few times I wanted to use SD on site I used a thumb drive and installed SD on it. That allows you to edit scripts on site without putting anything on the customer site.

The "increment on Save"check box is accessible from the show pane with the suitcase icon. I’m running SD 6A195

All the stuff for the suitcase view in the show pane can be read and found in the document properties in SD. e.g.:

		bundle ID of document 1
		marketing version of document 1
		copyright of document 1
		build number of document 1

You can read those values directly from the bundle by getting the bundle object and using infoDictionary to read the values and put them into a dictionary that can be looked at. This is done by using

set TheBundle to current application's NSBundle's bundleWithPath:ThePath
TheBundle's infoDictionary's objectForKey:"CFBundleShortVersionString"

Added 11/27/16:
ThePath in the above example is a Posix path to the bundle, i.e. if the path to the script is /Users/bill/Desktop/Example script.scptd then ThePath is equal to /Users/bill/Desktop/Example script.scptd

For me running 10.11.6 El Capitan using AppleScript to read the BundleShortVersionString with Finder doesn’t work. So I just read the value from the bundle.


(Ed Stockly) #55

OK, I have a demo of the first project.

It requires Myriad Tables.

The dropbox folder contains a Read Me and the compressed demo, which includes the Editing applet and a Text Replacing applet with files.

The biggest issue is a Myriad Tables issue.

Is it possible to easily escape return and tab in Myriad Tables?


(Shane Stanley) #56

You can enter them using the option key, but if you want to use an escape-style equivalent, it’s up to you to define and use it. There’s no standard for such a thing. Some might find ^p familiar, or \r or \n. You just need to run a find-and-replace on the pairs before using them.

(Shane Stanley) #57


Why are you storing your stuff in Automator’s Workflows folder? You’re not saving workflows – you’re saving data to support your application. The correct place for that is in a folder in Application Support.

(Ed Stockly) #58

What do they mean by “workflows”?

I always though of the workflows folder as a place for anything related to appleScript workflows that scripts always have access to without worrying about permissions.

(Ed Stockly) #59

OK, I’m having issues with this. I’'ll see if I can minimize it. Basically I can enter return characters using the option key, and they do save and reload, but they aren’t recognized in the text replacements.

Also is it possible to adjust the row height in MT, so that if a return character is used we can see the second line (or the third or fourth, etc.)?

(Shane Stanley) #60

It was originally for Automator’s .workflow files, but it’s now used more generally for Automator stuff.