This is a two part question thread. I’m still in the ‘beginner’ grade of scripting.
The scenario: A p2p file-sharing application which will delete its connection file if the modification date is older than 30 days. I need to try to prevent this happening. Connection files should be good for at least 3 months.
I thought ideally a script running from within the application bundle would be ideal if it could ‘somehow’ be triggered to run as the main application is opening and change the connection file’s modification date. However I do not have a clue how to do this to the application bundle. And I suspect bundle info files are probably highly sensitive.
Second best solution I could put together: The workaround is a script that changes the connection file’s modification date, then launches the application.
If anybody has any ideas about the ‘ideal’ solution I would love to hear them.
In meantime, this is what I put together:
code checked out
Is there anything wrong with the design/layout of the script? It runs fine on my system.
If I cannot do the ‘ideal’ solution, then this script app will suffice but I would like some advice on creating an installer for this script app. if possible.
For the actual installer of the script app, this is what I put together:
(This is a post-install section of the script-app installer dealing with aliases of the script-app. This is where my questions lie.)
(Adding to Dock looks complicated. ‘I would have liked to replace the original application’s aliases with the script app’s aliases.’ But that looks like a major scripting job for advanced scriptors lol)
References: Create alias to desktop and Add items to Dock.
I have not tried this out yet other than it compiling ok. I’m a little nervous lol. Does this look right?
set the_choice to (choose from list {"Add to Dock", "Add alias to Desktop", "None"} with prompt "Add aliases for appname?:") as string
if the_choice is "false" then error number -128
try
if word 1 of the_choice is "Add" then
if word 3 of the_choice is "Dock" then
set the_file to "appname"
set persistent_what to "persistent-apps"
set this_file to POSIX path of (item i of the_file as alias)
do shell script "defaults write com.apple.dock " & persistent_what & " -array-add '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>" & this_file & "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>'"
tell application "Dock"
quit
repeat
try
activate
exit repeat
end try
end repeat
end tell
else if word 2 of the_choice is "alias" then
set apps_path to (path to At Ease applications folder from local domain) as string
try
set app_ref to (apps_path & "appname.app") as alias
on error -- app is not in Applications folder
set app_ref to (choose file with prompt "Where is the appname application?")
end try
tell application "Finder"
make alias to app_ref at desktop
end tell
else
if word 1 of the_choice is "None" then
close
end if
end if
end if
end try
I guess I could also put in an option for aliases to both desktop and dock choices.