Hi Everyone,
I have a fairly complicated script to do a pretty simple task, use the dropbox API to get a link to a given file or folder. I’m using something called Service Station to create an item in the context menu that runs the script. The problem is, I want the script to wait for the link if the file isn’t uploaded, and then present the link when it’s done, but instead the dialog just stays there until you manually dismiss it, and it doesn’t periodically check for the link again. I’m sure it’s something simple that I’m missing, but here’s the script. I also asked chat gpt for assistance, but no luck
on serviceStationDidSelect(targetedURL, selectedItemURLs, menuKind)
set inputPath to selectedItemURLs
set inputPath to POSIX path of inputPath
set outputPath to replaceText(inputPath, "/Volumes/Dropbox", "/Users/roccofiorentino/Audio Production Dropbox/Rocco Fiorentino")
try
set dropboxLink to do shell script "/Users/roccofiorentino/.pyenv/shims/python3 /Users/roccofiorentino/bin/get_dropbox_link.py '" & outputPath & "'"
if dropboxLink contains "https://" then
set the clipboard to dropboxLink
do shell script "afplay ‘/System/Library/Sounds/Purr.aiff'"
else
display dialog "The shell script produced this output: " & dropboxLink buttons {"OK"} default button "OK"
end if
on error errStr
if errStr contains "LookupError" then
repeat
display dialog "The file you requested hasn't finished uploading yet. Once the upload is complete, a link will be generated." buttons {"Please Wait…"} with title "Waiting for upload…"
delay 2
set dropboxLink to do shell script "/Users/roccofiorentino/.pyenv/shims/python3 /Users/roccofiorentino/bin/get_dropbox_link.py '" & outputPath & "'"
set errStr to ""
try
if dropboxLink contains "https://" then
set the clipboard to dropboxLink
do shell script "afplay ‘/System/Library/Sounds/Purr.aiff'"
exit repeat
end if
on error newErrStr
set errStr to newErrStr
end try
end repeat
else
display dialog "An error occurred: " & errStr buttons {"OK"} default button "OK"
end if
end try
end serviceStationDidSelect
on replaceText(inputString, findText, replaceText)
set AppleScript's text item delimiters to findText
set itemList to every text item of inputString
set AppleScript's text item delimiters to replaceText
set outputString to itemList as string
set AppleScript's text item delimiters to ""
return outputString
end replaceText
Code posting backticks added by NG.