I’m working on a script that creates a blank text file in a subfolder within a User’s Dropbox folder. For some reason the script below returns the error:
I’m not sure what’s causing this or what to try for here.
-- Path to Contacts folder
set DropboxContacts to (POSIX file "~/Dropbox/Contacts/") as string
tell application "Finder" to make new file at DropboxContacts with properties {name:"locked.txt"}
Obviously, I am a newbie to Apple Script. So, thanks for any help.
set DropboxContacts to ((path to home folder as text) & "Dropbox:Contacts:")
tell application "Finder" to make new file at folder DropboxContacts with properties {name:"locked.txt"}
or
tell application "Finder" to make new file at folder "Contacts" of folder "Dropbox" of home with properties {name:"locked.txt"}
In a message signed by Christopher Stone in the mailing list applescript-users@lists.apple.com
I found a piece of code which give a way to decipher paths starting with tilde.
set _dir to "~/Dropbox/Contacts/"
set fullDir to quoted form of (do shell script "echo " & _dir)
Yvan KOENIG (VALLAURIS, France) mardi 21 octobre 2014 20:00:34
We all have a public folder within our homefolder, unless we take special measures to make it go away.
There is a Drop box folder inside the Public folder, that mustn’t be taken for the ~/Dropbox folder you get when you get yourself a dropbox account. The Apple Drop Box folder is meant as a place where others can send you files I believe, whereas the Dropbox folder is a service, that lets you share contents between multiple machines (backup of important files, sharing of same configuration files etc.), thru software,. You can also share stuff with other users through links that you can create, so other poeple can download your stuff through the web.
I didn’t do anything custom when I installed Dropbox, my dropbox folder (with the custom icon in the Finder sidebar) is located in my home directory.
@ juskaiser
The Contacts folder of the Dropbox folder, is a custome one, that you’ll have to make inside the dropbox folder in order for the script to run.
I’ve since updated that to be a trifle faster and more versatile.
on resolveTildePath(tildePath, qfFlag)
if class of tildePath = text then
if tildePath = "~" or tildePath = "~/" then
set tildePath to POSIX path of (path to home folder)
else if tildePath starts with "~/" then
set tildePath to POSIX path of (path to home folder) & text 3 thru -1 of tildePath
end if
if qfFlag = true or qfFlag = 1 then set tildePath to quoted form of tildePath
return tildePath
else
error "Fault in handler: resolveTildePath()" & return & return & ¬
" Expected class of input: text" & return & ¬
" Actual class of input: " & class of tildePath
end if
end resolveTildePath
set _path to "~"
set path1 to resolveTildePath(_path, 0)
set _path to "~/"
set path2 to resolveTildePath(_path, false)
set _path to "~/Documents/"
set path3 to resolveTildePath(_path, 1)
set _path to "~/Dropbox/Public/"
set path4 to resolveTildePath(_path, true)
set _path to path to home folder
set path5 to resolveTildePath(_path, 1)