I have been attempting to make a simple application that copies a selected file to a predetermined directory, only the variable does not work when set in a shell script. I was wondering if there is a way to phrase the copy or move command to allow it to take effect. The script is below.
set filepath to POSIX path of (choose file with prompt "Chose your file")
delay
do shell script "cp " & filepath & " ~/Library/Application Support/"
It does not work because space characters in paths must be escaped, the most reliable way is to use quoted form of.
path to application support folder from user domain is the relative path to the current user's application support folder.
set applicationSupportFolder to POSIX path of (path to application support folder from user domain)
set filepath to POSIX path of (choose file with prompt "Chose your file")
do shell script "cp " & quoted form of filepath & space & quoted form of applicationSupportFolder
Related
I did the following and it works fine, I added my Command Line Tool to the Resource Folder of my project and did the following below:
set myPath to POSIX path of (path to resource "MyComandLineTool")
do shell script "cp " & quoted form of POSIX path of myPath & space & "/private/tmp" with administrator privileges
set cmd to "/private/tmp/myPath -r"
do shell script " " & cmd with administrator privileges
I wanted to know how not to pass it to /private/tmp, just run it from within the Resources folder of my project.
It's quite similar, just omit the copying part
set myPath to quoted form of (POSIX path of (path to resource "MyComandLineTool"))
do shell script myPath & " -r" with administrator privileges
Note: quoted form of is always good practice as the path could contain space characters
I have been struggling to make a basic program that copies selected files to a predetermined location. However it always ends up with the command having two different path types. is there any way that I can bypass this as it is bugging me and i have finished every other aspect of the program.
set targetFolder to (POSIX path of (path to home folder)) & "Library/Application Support/..." as POSIX file
set filepath to POSIX path of (choose file with prompt "Chose your file")
delay
do shell script "cp " & filepath & space & targetFolder
delay
display dialog "Your file has been moved!"
It's exactly the same as your previous question: Didn't you read my answer? You have to use quoted POSIX paths.
set applicationSupportFolder to POSIX path of (path to application support folder from user domain)
set filepath to POSIX path of (choose file with prompt "Chose your file")
do shell script "cp " & quoted form of filepath & space & quoted form of applicationSupportFolder
And you don't need any delays.
I'm developing a Mac OS X application and in some case it needs to copy a file to /Library/ScriptingAdditions.
And using the code below
tell application "Finder"
duplicate sourcePath to destinationPath with replacing
end tell
will prompt a dialog saying "Finder" wants to make some changes...
I would like to make the dialog saying My Application wants to make some changes....
I've read about https://developer.apple.com/library/mac/documentation/security/conceptual/authorization_concepts/01introduction/introduction.html
but it doesn't seem to work with AppleScript.
If you would use the shell instead of AppleScript, the dialog asking for the password will display the name of your own application. Here's an example that copies the file "_this is a test.xyz".
set sourcePath to "'~/desktop/_this is a test.xyz' " -- mind extra space
set destPath to path to scripting additions folder -- change this to your destination folder
set destPath to POSIX path of destPath
set destPath to "'" & destPath & "_this is a test.xyz'"
set shellScript to "cp -n " & sourcePath & destPath
do shell script shellScript with administrator privileges
Warning: don't just run this script without modification, as it will add an empty file to your scripting additions folder and you probably don't want that. This script just serves as an example to look at.
Edit:
This will only work if you can compile your app as an independent app. If you're using Python, you need to compile your Python scripts as a standalone app with a name. The password dialog will show the name of the standalone app instead of "Python".
I'm creating simple script to convert mp3 files using shell script. I decided to automate my conversion using applescript.
Basically what I'm doing is selecting mp3 file then splitting that file using my command line and i want to create a folder where the file is located (script will create that for me).
Now I just need to figure out how to get a path to a folder of the file.
How do I do that in applescript?
Here is the script that I have so far:
set mp3FileToSplit to choose file without invisibles
set thepath to mp3FileToSplit as text
set theposix to POSIX path of thepath
tell application "Finder" to set file_name to (name of mp3FileToSplit)
do shell script "/opt/local/bin/mp3splt -t 3.00 -d " & quoted form of file_name & " " & quoted form of theposix
Right now what that script does is creating folder on the root of my hard drive and I need to be in the folder where the file is located.
Any help will be appreciated.
tell application "Finder"
set f to POSIX file "/private/etc/" as alias
POSIX path of ((folder of f) as alias) -- /private/
end tell
Or
do shell script "dirname /private/etc/" -- /private
tell application "Finder"
set deletedfile to alias "Snow Leopard:Users:test.pdf"
delete deletedfile
end tell
The problem is I repeatedly call this script from my Cocoa application so the sound is played repeatedly too. Is it possible to disable that sound ?
Since the trash is just an invisible folder inside your home folder you can do this...
set myFile to (path to desktop folder as text) & "myFile.txt"
set trashFolder to path to trash folder from user domain
do shell script "mv " & quoted form of POSIX path of myFile & space & quoted form of POSIX path of trashFolder
one simple way (doesn't move to Trash)
do shell script "rm '/Users/test.pdf'"