Get path of parent folder of script location : Applescript

Simon

Background: I'm trying to write a simple applescript app that will launch a tcl app, but I'm getting stuck on the first part of the script.

I need to get the parent folder of the path to the applescript. When I run this code:

set LauncherPath to path to me
set ParentPath to container of LauncherPath

...I get this error:

error "Can’t get container of alias \"Macintosh HD:Users:simon:Downloads:folder with spaces:CrossFire-master:CrossFire Launcher for Mac.app:\"." number -1728 from container of alias "Macintosh HD:Users:simon:Downloads:folder with spaces:CrossFire-master:CrossFire Launcher for Mac.app:"

After reading this answer, I tried this:

set LauncherPath to path to me
set RealLauncherPath to first item of LauncherPath
set ParentPath to container of RealLauncherPath

...but I got this error:

error "Can’t get item 1 of alias \"Macintosh HD:Users:simon:Downloads:folder with spaces:CrossFire-master:CrossFire Launcher for Mac.app:\"." number -1728 from item 1 of alias "Macintosh HD:Users:simon:Downloads:folder with spaces:CrossFire-master:CrossFire Launcher for Mac.app:"

Any help or ideas much appreciated. Thanks in advance!

P.S. once I figure out the above problems, the full script will be something like this:

set LauncherPath to path to me
set RealLauncherPath to first item of LauncherPath
set ParentPath to container of RealLauncherPath
set UnixPath to POSIX path of ParentPath
set launcherCrossFire to "/usr/local/bin/wish " & UnixPath & "/CrossFire.tcl > /dev/null &" -- creat command to launch CrossFire
do shell script launcherCrossFire

UPDATE: Here's the working script incorporating the answer below:

set UnixPath to POSIX path of ((path to me as text) & "::") --get path to parent folder
set LaunchCrossFire to "/usr/local/bin/wish '" & UnixPath & "CrossFire.tcl' > /dev/null 2>&1 &" -- creat command to launch CrossFire
do shell script LaunchCrossFire -- run command
adayzdone

Try:

set UnixPath to POSIX path of ((path to me as text) & "::")

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Get the path of a closed folder with Applescript

From Dev

VBA 03 - Application Path - get to Parent Folder

From Dev

How to get path to the parent folder of a certain directory?

From Dev

Inno Setup - Get a path to parent folder

From Dev

VBA 03 - Application Path - get to Parent Folder

From Dev

Get iTerm location Applescript

From Dev

Get iTerm location Applescript

From Dev

Get Parent directory of a specific path in batch script

From Dev

AppleScript: execute script on selected folder

From Dev

Batch Script to Find a Folder inside Sub Folders and get Folder Path

From Dev

Mongodb parent reference tree get current location and full path

From Dev

How to get the name of the parent folder of a file specified by its full path?

From Dev

get relative path with just file name and name of the parent folder

From Dev

How to get spring boot application jar parent folder path dynamically?

From Dev

Programmatically get the folder location

From Dev

Windows Batch script - Get folder containing another folder, but not containing a certain parent folder

From Dev

How to get POSIX path of the current script's folder in JavaScript for Automation?

From Dev

Get virtualenv's bin folder path from script

From Dev

Batch Script to Find a Folder inside Sub Folders and get Path

From Dev

Get build folder path for Android Studio project via bash script

From Dev

How to get android outputs folder in Gradle build script (absolute path)

From Dev

AppleScript: Main Script reading from random folder

From Dev

AppleScript: Main Script reading from random folder

From Dev

Applescript exec shell script with space in path

From Dev

Script for "extracting" subfolders into parent folder

From Dev

Script for "extracting" subfolders into parent folder

From Dev

Add bash script folder to path?

From Dev

Applescript: Get path to .app without opening it

From Dev

Getting the parent path from a script

Related Related

  1. 1

    Get the path of a closed folder with Applescript

  2. 2

    VBA 03 - Application Path - get to Parent Folder

  3. 3

    How to get path to the parent folder of a certain directory?

  4. 4

    Inno Setup - Get a path to parent folder

  5. 5

    VBA 03 - Application Path - get to Parent Folder

  6. 6

    Get iTerm location Applescript

  7. 7

    Get iTerm location Applescript

  8. 8

    Get Parent directory of a specific path in batch script

  9. 9

    AppleScript: execute script on selected folder

  10. 10

    Batch Script to Find a Folder inside Sub Folders and get Folder Path

  11. 11

    Mongodb parent reference tree get current location and full path

  12. 12

    How to get the name of the parent folder of a file specified by its full path?

  13. 13

    get relative path with just file name and name of the parent folder

  14. 14

    How to get spring boot application jar parent folder path dynamically?

  15. 15

    Programmatically get the folder location

  16. 16

    Windows Batch script - Get folder containing another folder, but not containing a certain parent folder

  17. 17

    How to get POSIX path of the current script's folder in JavaScript for Automation?

  18. 18

    Get virtualenv's bin folder path from script

  19. 19

    Batch Script to Find a Folder inside Sub Folders and get Path

  20. 20

    Get build folder path for Android Studio project via bash script

  21. 21

    How to get android outputs folder in Gradle build script (absolute path)

  22. 22

    AppleScript: Main Script reading from random folder

  23. 23

    AppleScript: Main Script reading from random folder

  24. 24

    Applescript exec shell script with space in path

  25. 25

    Script for "extracting" subfolders into parent folder

  26. 26

    Script for "extracting" subfolders into parent folder

  27. 27

    Add bash script folder to path?

  28. 28

    Applescript: Get path to .app without opening it

  29. 29

    Getting the parent path from a script

HotTag

Archive