| |
| | |

Apple Phoon Forum

 Forgot password?
 Register
View: 1941|Reply: 12

How do I create a UNIX path to a file inside Application Support?

[Copy link]

Post time: 2014-01-09 21:11:11 |Show all posts
I need to create a path that uses "/" to seperate the location. It needs to be variable on the user. The code I'm having trouble with is this section: (Some of the variable I have not specified in this post because they serve no purpose to my question.
set appName to "Mc_Launcher"set subFolder to "Mc_Log.txt"set permPath to (POSIX path of ((path to application support folder from user domain) & Mc_Launcher & subFolder))set FileTXT to (("Login on " & (current date) & " successful, took " & timer & " seconds to complete.") as text)set ShellLog to ("echo " & FileTXT & ">> " & permPath)do shell script ShellLog   
Reply

Use magic Report

Post time: 2014-01-10 16:15:13 |Show all posts
I don't have Minecraft to fully test the script, but the permissions error is from transposing the LogTXT and FileTXT variables in your ShellLog command.
Reply

Use magic Report

Post time: 2014-01-10 14:33:24 |Show all posts
I think it would just be easier to provide you with my whole code. I'm getting the error "You do not have permission".
Reply

Use magic Report

Post time: 2014-01-10 12:46:24 |Show all posts
You are correct about the path delimiters - normally one would pick one way or the other, but the folder and file creation statements were not included. It looks to me like Finder and POSIX paths (or pieces of paths) are getting mixed up, and perhaphs the Finder is being used to create the folder and file with the wrong delimiter.
Reply

Use magic Report

Post time: 2014-01-10 10:50:08 |Show all posts
Seeing that directory name with the slash in it in the Finder got me curious. There is no way to make a directory with a slash in it from the terminal ,The shell will always take the '/' as a delimiter.
But the Finder doesn't care you can make a folder in Finder with a slash in the name. When you go to terminal and look at it with ls the slash in Finder is turned into a ':' (colon). And the terminal doesn't care if you put a colon in a directory name but if you do the Finder displays that as a slash.
Just thought it was interesting and could explain what the OP saw.
Reply

Use magic Report

Post time: 2014-01-10 09:33:09 |Show all posts
It looks like you are having a similar problem with the part of the script that makes your folder, so I have separated them below. The statements used will create the folder and file if needed, and there won't be an error if they already exist.
# create folder and file if needed
set appName to "Mc_Launcher"
set baseFolder to (POSIX path of (path to application support folder from user domain) as text) & appName
do shell script "mkdir -p " & quoted form of baseFolder
set logFile to "Mc_Log.txt"
set permPath to baseFolder & "/" & logFile
do shell script "touch " & quoted form of permPath
# write to log file as needed
set FileTXT to "Login on " & (current date) & " successful, took " & timer & " seconds to complete."
set ShellLog to ("echo " & FileTXT & " >> " & quoted form of permPath)
do shell script ShellLog


Reply

Use magic Report

Post time: 2014-01-10 08:00:55 |Show all posts
Interesting, the script works OK for me. The only problem is if the directory Mc_Launcher doesn;t exist the script throws an error.
Did you copy red_menace's script or did you make mods to your script? Post back with your script.
regards
Reply

Use magic Report

Post time: 2014-01-10 06:03:43 |Show all posts
Thank you for the help, just one minor error. For some reason it generated a file with the name "Mc_Launcher/Mc_Log.txt". Anyway to fix this?


Reply

Use magic Report

Post time: 2014-01-10 04:37:21 |Show all posts
Oh in the do shell script right? that's because the folder Appliction Support has a space in it and the shell gets confused.
try
set ShellLog to ("echo " & FileTXT & ">> " & quoted form of permPath)
Message was edited by: Frank Caggiano quoting the echo text is a good idea but isn;t strictly needed as echo takes everything on the line as input.
Reply

Use magic Report

Post time: 2014-01-10 03:13:57 |Show all posts
You need to make sure that the file path has any spaces or other special characters escaped or quoted for the shell, for example:
set appName to "Mc_Launcher"
set logFile to "Mc_Log.txt"
set permPath to (POSIX path of ((path to application support folder from user domain) as text) & appName & "/" & logFile)
set FileTXT to (("Login on " & (current date) & " successful, took " & timer & " seconds to complete.") as text)
set ShellLog to ("echo " & quoted form of FileTXT & " >> " & quoted form of permPath)
do shell script ShellLog


Reply

Use magic Report

Post time: 2014-01-10 01:34:29 |Show all posts
For some reason the file path I'm getting is "/Users/AlexanderLieflander/Library/Application" and then the input it's giving is "/Support [The text I want to have in it]".
Reply

Use magic Report

Post time: 2014-01-10 00:18:28 |Show all posts
What trouble are you having?

POSIX path of (path to application support folder from user domain)
Will give you a POSIX path (path delimited by '/') that will be set to the current users home folder.
Reply

Use magic Report

Post time: 2014-01-09 22:31:57 |Show all posts
It really isn't any good your asking here: this forum is for Apple's long-defunct office suite AppleWorks. You should go to https://discussions.apple.com/community/mac_os and pick the version of OSX relevant to your Mac, and ask there.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Archive| Apple Phoon

2021-04-18 05:54 GMT-8 , Processed in 0.083983 sec., 27 queries .

Powered by Discuz! 7.2

Release 20121101, © 2001-2021

To Top