How to create short-cuts in the Dock

http://macscripter.net/viewtopic.php?id=43555

alastor933 suggested me to start a new thread for this. So here I’m.

I have a script that copies the “General_Scripts” folder (containing scripts) to the User’s desktop and the pdf presets files from the “PDF_Presets” folder to the user’s settings.

-- Copies the scripts to Desktop
-- Copies the PDF Preset to the Preset folder

set userApplicationSupportFolder to path to application support folder from user domain as text
tell application "Finder"
	set theLocation to target of front window
	
	-- Copies the scripts to Desktop
	duplicate (folder "General_Scripts" of theLocation) to desktop with replacing
	
	-- Copies the PDF Preset to the Preset folder
	duplicate (every file of folder "PDF_Presets" of theLocation) to folder (userApplicationSupportFolder & "Adobe:Adobe PDF:Settings") with replacing
	
end tell

The script is working fine without any problem. Thanks to StefanK who helped me with the script:
http://macscripter.net/viewtopic.php?pid=178183#p178183

Now the query is that I would like to create shortcuts of for all the AppleScript files (scripts from the Desktop/“General_Scripts” folder) to my dock, replacing the older ones if there is any in the Dock. Currently there are 8-10 scripts, it might be less or more.

The script for creating the shortcuts will follow the base script. i.e. it will first copy the necessary files to the system and later creates shortcuts in the Dock.

Thanks in advance.

I modified Luther Fuller’s script here to work with files.

First, you need to modify your current script like so:

-- Copies the scripts to Desktop 
set dupFolder to duplicate (folder "General_Scripts" of theLocation) to desktop with replacing -- MODIFIED
set theFiles to files of dupFolder as alias list -- ADDED

Then add this at the end:

repeat with fileAlias in theFiles
	addDockMenu(fileAlias)
end repeat
----------------------------------------------------------------------------
-- Create Dock item for the passed file
-- Adapted from a script by Luther Fuller:
-- http://lists.apple.com/archives/applescript-users/2009/Oct/msg00124.html
-- parameter:	[alias]		the file to be put into the Dock
-- returns:		[]			nothing
----------------------------------------------------------------------------
on addDockMenu(fileAlias)
	-- 1 construct the |file-data| record
	set filePath to POSIX path of fileAlias
	set newFileData to {|_CFURLString|:filePath, |_CFURLStringType|:0}
	
	-- 2 construct the |tile-data| record
	tell application "Finder" to name of fileAlias
	set newTileData to {|file-data|:newFileData, |file-label|:result, |file-type|:40}
	
	-- 3 construct the newMenuFileItem record
	set newMenuFileItem to {|tile-data|:newTileData, |tile-type|:"file-tile"}
	
	-- 4 write to Dock preferences file
	set prefsFile to (path to preferences from user domain as text) & "com.apple.dock.plist"
	tell application "System Events"
		set dockRec to value of property list file prefsFile
		set |persistent-others| of dockRec to |persistent-others| of dockRec & {newMenuFileItem}
		set value of property list file prefsFile to dockRec
	end tell
	tell application "Dock" to quit
	
end addDockMenu

NotaBene: I’m still on 10.6.8. This may not work “out of the box” on 10.9 or later. Preferences are cached there, and it may seem the actual plist is ignored. A way around this is described here.