I made this script that is bundled into an app that lives in our team’s dock, and when we have a new project open in our project management software that lives in a browser, the app grabs the name of the project, and makes a new folder complete with subfolders in our shared dropbox.
My question is, is it possible for the script inside the app itself to “know” when a new user runs the app for the first time, and prompt the user to choose the dropbox folder they already have set up, and have it write that folder path into the app?
I also plan to have the “first time” popup let the user choose Safari or Chrome, so I can just deliver the app to new members instead of having to set it up myself.
(*
If user uses Chrome, this is correct.
*)
tell application "Google Chrome"
set the_url to the title of active tab of front window
end tell
(* If user uses Safari, this is correct.*)
(*
tell application "Safari"
set the_url to the name of front document
end tell
*)
(*
This is the location of the main folder.
This folder has to exist or nothing will happen.
The folder location is:
/Dropbox/Team Folder/0 - Working Files/The Name of users jobs folder.
See example below and edit accordingly.
*)
set theLocation to POSIX path of (path to home folder) & "Dropbox/Team Folder/0 - Working Files/example/"
set myIcon to (path to me as text) & "Contents:Resources:My Icon.icns"
try
set folderpath to POSIX path of theLocation & the_url
set folderStructure to "/{'Artwork','Assets','Final'/{'Final Artwork','Final Package'}}"
do shell script "/bin/mkdir -p " & quoted form of folderpath & folderStructure
set theFile to POSIX file folderpath
tell application "Finder"
activate
open theFile
end tell
on error the error_message number the error_number
display dialog "Error: " & the error_message buttons {"OK"} default button 1 with icon alias ((path to me) & "Contents:Resources:My Icon.icns" as string)
end try
Create one plain text file with 1 entry for starting (is “NoUsersYet” & RETURH):
"NoUsersYet
"
First I have this file on the desktop, only for testing purposes.
Then you can put this file in app’s bundle, in resources folder.
Then you can write script with following way:
set the current_user to (get the long user name of (system info)) as string
set usersListFile to POSIX file "/Users/123/Desktop/UsersList.txt"
set users_List to paragraphs of (read usersListFile)
set default_browser to get_default_browser()
set the_url to get_theURL(default_browser)
if the_url = "" then
display dialog "Application will terminated!
Open webpage with your default browser and try again" buttons {"OK"}
return
end if
if not (current_user is in users_List) then
write (current_user & return) to usersListFile starting at eof
tell me to activate
set the_location to choose folder with prompt "Please, choose your working folder inside the dropbox"
set the_location to POSIX path of the_location
write (the_location & return) to usersListFile starting at eof
else
set the_location to readTheLocation(current_user, users_List)
end if
set myIcon to (path to me as text) & "Contents:Resources:My Icon.icns"
try
set folderpath to (the_location & the_url)
set folderStructure to "/{'Artwork','Assets','Final'/{'Final Artwork','Final Package'}}"
do shell script "/bin/mkdir -p " & quoted form of folderpath & folderStructure
set theFile to POSIX file folderpath
tell application "Finder"
activate
open theFile
end tell
on error the error_message number the error_number
display dialog "Error: " & the error_message buttons {"OK"} default button 1 with icon alias ((path to me) & "Contents:Resources:My Icon.icns" as string)
end try
on get_theURL(default_browser)
set the_url to ""
if default_browser is "com.apple.safari" then
if application "Safari" is running then
tell application "Safari"
activate
set the_url to the name of front document
end tell
end if
else if default_browser is "com.google.chrome" then
if application "Google Chrome" is running then
tell application "Google Chrome"
activate
set the_url to the title of active tab of front window
end tell
end if
else
-- other browsers checking
end if
return the_url
end get_theURL
on get_default_browser()
set default_browser to do shell script "x=~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist; \\
plutil -convert xml1 $x; \\
grep 'https' -b3 $x | awk 'NR==2 {split($2, arr, \"[><]\"); print arr[3]}'; \\
plutil -convert binary1 $x"
end get_default_browser
on readTheLocation(current_user, users_List)
repeat with i from 1 to ((count of users_List) - 1)
set next_user to item i of users_List
if next_user = current_user then
set the_location to item (i + 1) of users_List
exit repeat
end if
end repeat
return the_location
end readTheLocation