AppleScript: How to let AppleScript use the same environment as Bash shell does?

Howdy!
I can run AppleScript from Bash shell.
I can also run Bash shell from AppleScript.
So my question is when I run a Bash shell script from AppleScript, I am hit with a path problem.
Suppose my AppleScript is under ~user/a.scpt. I want my AppleScript to know its current path (i.e. ~user/a.scpt).
So a quick snippet test in my AppleScript shows that AppleScript always begins from the root directory:
do shell script "pwd"
So let's do a workaround AppleScript like this:
tell application "Finder" to set currentDir to (target of front Finder window) as text
do shell script "cd " & (quoted form of POSIX path of currentDir) & "; pwd"
This works. However, this approach poses a potential danger.
Suppose when I run this AppleScript for a bash script, I inadvertently clicked other Finder Window. That would result in execution of bash script in that newly clicked Finder Window, resulting in a big mess.
Is there a better way to let the AppleScript to know its current path?

The following is what your Applescript environment looks like, so plan accordingly.  If you want your Applescripts to be portable to other user environments, you should NOT depend on your environment, but rather embed all the environment knowledge you need into your script.
Applescript "do shell script" environment
pwd:
/bin/ls -dlaeO@ .
drwxr-xr-x  36 root  wheel  - 1292 Feb 28 09:58 .
    /usr/bin/id -a
uid=501(raharris)
gid=20(staff)
groups=20(staff),
402(com.apple.sharepoint.group.1),
12(everyone),
61(localaccounts),
79(_appserverusr),
80(admin),
81(_appserveradm),
98(_lpadmin),
403(com.apple.sharepoint.group.2),
33(_appstore),
100(_lpoperator),
204(_developer),
398(com.apple.access_screensharing),
399(com.apple.access_ssh)
$#
0
$0
/path/to/your/shell/script
printenv:      
SHELL=/bin/bash
TMPDIR=/var/folders/4t/t1djbq6j5pj951x44l9hwxtc0000gn/T/
Apple_PubSub_Socket_Render=/tmp/launch-mSKKJo/Render
USER=<username_running_the_Applescript>
SSH_AUTH_SOCK=/tmp/launch-7D4zpF/Listeners
__CF_USER_TEXT_ENCODING=0x1F5:0:0
PATH=/usr/bin:/bin:/usr/sbin:/sbin
__CHECKFIX1436934=1
PWD=/
HOME=/Users/<home_dir_of_running_user>
SHLVL=2
LOGNAME=<username_running_the_Applescript>
DISPLAY=/tmp/launch-qKucki/org.macosforge.xquartz:0
_=/usr/bin/printenv
Message was edited by: BobHarris

Similar Messages

  • I recently bought iphone6, My imessage and face time is not working and still it charged me for normal text message multiple times and still not able to authorise the usage. Let me know how I can start using the same.

    I recently bought iphone6, My imessage and face time is not working and still it charged me for normal text message multiple times and still not able to authorise the usage. Let me know how I can start using the same.

    Hello vinay34,
    If you are having issues with activating your Apple ID for FaceTime and iMessage, then take a look at the article below to get it sorted out. Make sure that you have the Date and Time set to Automatic as well as any other steps listed in the article. 
    iOS: Troubleshooting FaceTime and iMessage activation
    http://support.apple.com/en-us/ts4268
    Regards,
    -Norm G. 

  • I have a wireless network at home. I run my iphone and ipad on it with no problems. Just purchased a MacBook Pro, and now my wi-fi keeps disconnecting and i get an error message saying another device is using the same IP address. What does all this mean?

    I have a wireless network at home. I run my iphone and ipad on it with no problems. Just purchased a MacBook Pro, and now my wi-fi keeps disconnecting and i get an error message saying another device is using the same IP address. What does all this mean?

    Hello AKCamus
    To give you some ideas of what to do next, I have provided a few articles that will give some troubleshooting Wi-Fi connections and recommended Wi-Fi settings.
    iOS and OS X: Recommended settings for Wi-Fi routers and access points
    http://support.apple.com/kb/HT4199
    iOS: Troubleshooting Wi-Fi networks and connections
    http://support.apple.com/kb/ts1398
    Troubleshooting Wi-Fi issues in OS X Lion and Mac OS X v10.6
    http://support.apple.com/kb/HT4628
    Thanks for using Apple Support Communities.
    Regards,
    -Norm G.

  • My husband and I use the same Itunes account/ID.  Does that mean we cannot both use FaceTime?

    My husband and I use the same itunes account/ID.  Does that mean we cannot use Facetime?

    Settings App > iTunes & App Store > Automatic Downloads [turn off the catagories you do not wish to be auto-downloaded].
    You will want to do this on both devices

  • How can I have use the same div ID multiple times on the same page?

    Okay so a problem I encounter a lot is that often times I want to use the same div ID several times on the same page. An example of this is when I'm creating table like designs.
    Let's say for instance I create a div ID called 'product-container'. I want to use 'product-container' multiple times on the same page but if I do this it is improper XHTML and will throw errors in any XHTML validator (you are only allowed to use a div ID once on any XHTML page in order for it to be standards compliant).
    Now the first option is that I could define 'product-container' in my CSS style sheet multiple times by doing something like this...
    #product-container {
         width: 300px;
    #product-container-2 {
         width: 300px;
    #product-container-3 {
         width: 300px;
    #product-container-4 {
         width: 300px;
    What you will see there however is that it seems pointless to define the same ID numerous times over (just adding a number on the end) when each ID is the exact same thing and has the exact same attributes.
    Now what I have noticed is that there are some sites out there who manage to have the same ID appear several times in the code but add a number to it just like above. The difference is that they only have one definition for 'product-cointainer' in their CSS document but in their actual XHTML code they have IDs for 'product-container' but with numbers on the end like 2,3,4,5, etc. It's almost as if JavaScript or some other code is automatically appending a number on the end of the ID so the validator won't consider the markup to be invalid, but yet it knows that it's using the same 'product-container' style that is contained in the CSS style sheet.
    I hope I explained this correctly. I'm just hoping to find a way that I can put the same div ID on a page multiple times without having to define it over and over again in my CSS.
    Any help is much appreciated!

    Because it seems like by using a class you can't make this position as 
    well as you can by using an ID. Am I wrong?
    An ID name can be used only one time per page.  A class name can be used multiple times per page.
    .product {
    width: 300px;
    text-align:left;
    color: #FF0000
    border: 2px solid #666;
    Nancy O.
    Alt-Web Design & Publishing
    Web | Graphics | Print | Media  Specialists
    www.alt-web.com/
    www.twitter.com/altweb
    www.alt-web.blogspot.com

  • HT204053 Hi, my husband has downloaded ios7 and now he is receiving my iMessages/facetime calls.  Obviously we both use the same apple Id.  How do i keep using the same apple id on both devices, but disable my iMessages etc from his phone??

    My husband has upgraded ios7.  His iphone and mine have the same apple id.  he has activated "icloud" which i have never activated before.  He is receiving my imessages and facetime calls. How do i disable this yet still continue using our shared apple id on both devices????
    thanks

    Short term solution, do this on both devices
    Settings > iCloud > Shut off anything you don't want shared
    Long term solution (actual solution)
    You need seperate Apple IDs for iCloud. iTunes and iCloud are not the same.
    Create a new Apple ID > https://appleid.apple.com/cgi-bin/WebObjects/MyAppleId.woa/
    On one of the devices go Settings > iCloud > Delete Account > Sign in with the new Apple ID
    This will seperate your Contacts, Calendars, Messages etc.
    You both can continue to use the same Apple ID for iTunes and share apps and music

  • TS1398 We a trying to start a apple ID acc for my daughters new IPod touch. I have a apple ID acc with mt Iphone. It wont let us use the same email address, but wont let us use a fake one either. What do we do?

    we are trying to open a apple ID acc for my daughters IPod touch.I have a apple ID acc with my IPhone. It wont let us us use the same email ( she doesnt have one) but wont let us us a fake one. What do we do?

    The only way to get an apple ID is to have an email account you've never used before. The only thing you can do is make her an email.

  • I have a new ipod and when I sign in to Words with Friends it says that user name is already in use. How can I continue using the same user name with a different ipod?

    I have a new ipod and added all my apps to it. When I sign in to Words with Friends it says that "user name is already in use" because it is linked to my old ipod. How can I use the same user name with my new ipod?

    Was the iPod setup via iTunes on this computer?
    Setup via wifi?
    Was the iPod previous synced to another iTunes library/computer?
    Have you successfully synced from this iTunes library/computer before?
    Do the songs play in iTunes?           
    Do you have the right boxes checked to sync?
    iTunes: Syncing media content to iOS devices and iPod        
    Try syncing using the manual method                 

  • How many devices can use the same rescue email?

    I support over 40 ipads at  my school. I want teachers to set up a rescue email that comes to me in case they are locked out. How many different apple ids can use the same rescue email address
    ?

    iTunes Store Support
    http://www.apple.com/emea/support/itunes/contact.html
    It would be best to address your questions there, especially since this is a public forum, and over there you could post more private issues with this set-up. Not to mention, getting more official answers.

  • How can multiple users use the same Creative Cloud Individual on one single-machine?

    We have one shared graphics workstation, which is infrequently in use by different people - therefore we bought a single-workstation license (which we were referred to "Creative Cloud Individual"). In the FAQs it says it installs locally, but whenever a user different from the installing adminstrator logs in, he is forced to use the trial.
    Is there a way to make the local installation usable on that single machine for multiple users?
    Thanks in advance for your reply

    Serenatasystems do the other users not have administrator access?  What happens if they sign in using the Adobe ID tied to your Creative Cloud subscription?  Do your Adobe Creative applications then exit trial mode?

  • HT204074 All of our devices have the same apple id (2 iphone 4's & 1 Windows Comp..) How can we seperate them but also allow them to still use the same itunes account?

    I tried to ask a similar question before, however did not understand our issues well enough to even form a comprehensive question and the kind replies.
    I apologize, unfortunately I've yet to resolve our problem.
    All of our devices are under the same Apple ID & password (an IPhone 4s, an IPhone 4, and a Dell Laptop that uses Windows 7.) How in the world can
    we separate them (so we can both use our free 5GB under the iCloud storage that each of our IPhone's offer, but "also" still use the same shared ITunes
    account?
    As it stands right now, my son's phone (iPhone 4) is set up under our Apple ID & pw-which enables him to use the free 5gb's under the iCloud.
    I cannot take advantage of the Free 5gb's iCloud on my IPhone 4s, because it's all "my info." on my son's phone (my email address & pw=what we've always used for our shared ITunes acct.)
    A big fat mess I know, and don't even want to confuse things by asking about these SMTP's...1 thing at a time!
    Not sure if it is still on his phone, however in trying to resolve this issue last time I set him up with a MobileMe address. I believe I entered my info back into his phone because it created a bigger mess!
    Thank you in advance for any suggestions/help! It's taken me some time to gather the patience and courage to ask for help again in resolved this
    issue!

    I don't know if I'm asking this all in a way that can be understood? Thanks ED3K, however that part I do understand (in the link you provided!)
    What I need to know is "how" I can separate or rather create another Apple ID for my son-who is currently using "my Apple ID?" If there is a way to let him keep "all" his info on his phone (eg-contacts, music, app's, etc.) without doing a "reset?') Somehow I need to go into his phone's setting-create a new Apple ID and possibly a new password so he can still use our combined iCloud & Itunes account?
    Also then letting me take back my Apple ID & password, but again allowing us (my son and I) to use the same iCloud & Itunes account? Does that make more sense??? I'm sincerely trying to get this cleared up once and for all----just need guidance from someone who has a true understanding of the whole Apple iCloud/Itunes system!
    Thanks again for "anyone" that can help me!!!

  • Me and my partner are currently using the same apple id and have no space left on our devices. We are currently waiting on the iphone 6 plus to arrive and don't know how to transfer all data to the new phones.

    Me and my partner are currently using the same apple id and have no space left on our devices. We are currently waiting on the iphone 6 plus to arrive and don't know how to transfer all data to the new phones.?

    I don't know if I'm asking this all in a way that can be understood? Thanks ED3K, however that part I do understand (in the link you provided!)
    What I need to know is "how" I can separate or rather create another Apple ID for my son-who is currently using "my Apple ID?" If there is a way to let him keep "all" his info on his phone (eg-contacts, music, app's, etc.) without doing a "reset?') Somehow I need to go into his phone's setting-create a new Apple ID and possibly a new password so he can still use our combined iCloud & Itunes account?
    Also then letting me take back my Apple ID & password, but again allowing us (my son and I) to use the same iCloud & Itunes account? Does that make more sense??? I'm sincerely trying to get this cleared up once and for all----just need guidance from someone who has a true understanding of the whole Apple iCloud/Itunes system!
    Thanks again for "anyone" that can help me!!!

  • How to have 2 Users on 1 Mac and both be able to use the same iTunes Library?

    We are using 1 Mac with 2 Users, how can we both use the same iTunes Library?

    Thanks Allen, However I have found another article that best applies to my situation.
    http://support.apple.com/kb/HT1203

  • HT201272 I have always had and used the same Apple ID, so where are the rest of the songs I bought from itunes? I've bought at least 400 songs and I only am being able to download 178. Where are the rest of my purchases?!

    I have always had and used the same Apple ID. I have changed credit card information on my Apple ID account several times though. Does that make a difference when downloading past purchases? I'm very angry at Apple and Itunes because I have been using itunes since 05/2005 and I do not have even close to the amount of songs and albums that I have purchased from itunes. If the credit card info does make a difference even though the account is the same one then itunes needs to make sure to notify users of this because I am not the only one who is wondering this same thing. I have numerous friends who i've talked to about this and they say the same thing, that they too have songs purchased in the past that have disappeared when trying to download past purchased items. It should not make a difference. $12 is $12. Especially since I have ALWAYS used the same account. If itunes does not change their ways, I will not be purchasing songs or anything else for that matter from them ever again. I will go back to buying CDs where I KNOW that it will always be with me and I don't have to deal with this. I will also make sure to find a better more reliable source to download music from and will make sure everyone I know and come in contact with knows what it is and how much better it is than itunes. There should be no experation date on the music I PURCHASE, nor should there be any other little loop holes that allow itunes to rob us of rightfully purchased products. What's the deal itunes?? 

    mannyace wrote:
    Thanks for the response.
    So I basically won't run into any trouble? I
    There should be no issues. Its designed to work like that.  You don't change Apple IDs just because you get a new device.
    mannyace wrote:
    Thanks for the response.
    Is there any chance that the phones can fall out of sync?
    Unlikely. But nothing is impossible.   Though I don;t see how that would happen. As long as both are signed into the Same Apple ID / iCloud Account they will be N'Sync. (Bad Joke)
    mannyace wrote:
    Thanks for the response.
    If I get a message or buy an app or take a photo on the iPhone 5, how do I get those things onto the iPhone 6?
    If you buy an App, you have 2 ways to get it to the iPhone6: If Automatic Downloads is enabled in Settings->iTunes & App Store, it will automatically download to the iPhone 6 when you buy it on the 5 and vice versa if you buy it on the 6, it will download to the 5.
    Alternatively, you can simply go to the App Store App->Updates->Purchased and look for the App there and download it. Purchased Apps will not require payment again. i.e They'll be free to download to the iPhone 6 once purchased.
    SMS Messages will sync over using Continuity as long as they are on the same Wifi network. Otherwise, restoring the iPhone 5 backup to the iPhone 6 will transfer all messages received up until the backup was made onto the iPhone 6.
    Images, can be transferred either through Photo Stream
    My Photo Stream FAQ - Apple Support
    Or any Cloud service you want such as Dropbox, or One Drive.
    mannyace wrote:
    Also, something i forgot to ask initially: Should I update the iPhone 5 to iOS 8 first or does that not matter?
    If you want the Continuity features as explained above you need to update the iPhone 5 to iOS 8. Otherwise its not all that important.

  • How to use the same apple id on two different iphones with different sync?

    Hi all,
    I own an iPhone 4s for personal use. Soon my company is going to give me a business phone and I can choose to have another iPhone. I'd love it but I don't know if what I wanna do is possible.
    Let's say I will have iPhone P (personal) and iPhone B (business) and Apple ID MyID.
    At the moment on iPhone P with account MyID I have application App1, App2, ... App9, I have contacts Cont1, Cont2, ...Cont9, I have songs Song1, Song2, ... Song9. All these are synced on my personal PC via iTunes and stored in the iCloud.
    When I'll get iPhone B I'd love to be able to use on it my Apple ID MyID and to sync it with my business PC (so NOT the same one I use for iPhone P).
    The configuration I'd love to have would be the following.
    iPhone P
    - Applications: App1, App2, App3, App8, App9
    - Contacts: Cont1, Cont2, ... Cont9
    - Songs: Song1, Song2, ... Song9
    iPhone B
    - Applications: App4, App5,App6, App7, App8, App9, App10 etc.
    - Contacts: Cont1, Cont2, Cont10, Cont11, ..., Cont20
    - Songs: Song1, Song2, Song10, Song11, ... Song20
    So will it be possible using the same Apple ID MyID on both iPhones to have this configuration? Some apps, contacts and songs in common and some differents?
    If so, how should I configure the two iPhones and the two PCs?
    Kind regards.

    If you use the same Apple ID for iCloud on each device, yes. However, you can use the same Apple ID for iTunes content on each device, but different Apple ID's for iCloud, iMessage, FaceTime, etc., on each device. That way, you can have whatever iTunes content you want on each phone, but keep all of the other data separate. You can create another Apple ID here:
    https://appleid.apple.com/cgi-bin/WebObjects/MyAppleId.woa/wa/createAppleId?loca lang=en_US
    Must be a verified email address.

Maybe you are looking for