Results 1 to 6 of 6
  1. #1
    Why does this simple apple script generate an error?
    I named the script below ToggleShowHiddenFiles.scpt. When I run the script I get this error:

    ./ToggleShowHiddenFiles.scpt
    ./ToggleShowHiddenFiles.scpt:134:140: script error: Expected “then”, etc. but found identifier. (-2741)


    The syntax appears correct, can anyone tell me how to avoid this error?



    #!/usr/bin/osascript


    tell current application
    set HiddenStatus to do shell script "defaults read com.apple.finder AppleShowAllFiles"
    if Hidden Status = "NO" then
    do shell script "defaults write com.apple.finder AppleShowAllFiles YES && killall Finder"
    else
    do shell script "defaults write com.apple.finder AppleShowAllFiles NO && killall Finder"

    end if
    end tell

  2. #2
    Why does this simple apple script generate an error?
    Mark FX's Avatar
    Member Since
    Aug 13, 2011
    Location
    West Sussex, UK
    Posts
    200
    Rep Power
    9
    Firstly your syntax is incorrect.
    You have written "set HiddenStatus to ect.", then you test for "if Hidden Status = ect.", so the variable spelling is not the same.

    Also you do not need the "tell current application" "end tell" block to run a do shell script command.

    It's also worth stating what version of OS X and AppleScript you are using, as the "AppleShowAllFiles" key is not valid on my system, which means your using a different version to myself and others who may be wanting to help you.
    This OSX version declaration is also important, as the AppleScript language has gone through various changes since OSX 10.6, although these changes are mostly to do with the AppleScriptObjC language used in Xcode, it still may be relevant to someone trying to help with your code.

    Regards Mark

  3. #3
    Why does this simple apple script generate an error?
    cradom's Avatar
    Member Since
    Feb 14, 2004
    Location
    Groves, Texas
    Posts
    4,781
    Your Mac's Specs
    21in. iMac 10.11 --- HP Linux Mint 18
    Rep Power
    22
    Quote Originally Posted by Mark FX View Post
    Firstly your syntax is incorrect.
    You have written "set HiddenStatus to ect.", then you test for "if Hidden Status = ect.", so the variable spelling is not the same.
    Where is that? He is getting the result of a defaults read and comparing it. If it's no then he's changing it to yes. I see no ect anywhere in the script.
    To the OP: try putting the Then on a separate line? I don't think Applescript is that syntax picky but you never know.
    Any priest or shaman must be presumed guilty until proved innocent.

  4. #4
    Why does this simple apple script generate an error?
    Mark FX's Avatar
    Member Since
    Aug 13, 2011
    Location
    West Sussex, UK
    Posts
    200
    Rep Power
    9
    @ cradom

    Read the AppleScript code posted.

    The poster is setting a variable called "HiddenStatus" to the result of the defaults read command.
    And then checking with an if statement a variable called "Hidden Status", which has a space in it.
    That is incorrect syntax.
    You have to check the variable in the if statement with the exact same spelling and case, and with no spaces in it.
    The ect. I've used in reply, is for me to eliminate duplicating the correct code following the mistake, although I've typed it wrong, it should be etc.

    Mark
    Last edited by Mark FX; 09-23-2015 at 01:00 PM.

  5. #5
    Why does this simple apple script generate an error?
    cradom's Avatar
    Member Since
    Feb 14, 2004
    Location
    Groves, Texas
    Posts
    4,781
    Your Mac's Specs
    21in. iMac 10.11 --- HP Linux Mint 18
    Rep Power
    22
    Ah, ok. Was wondering about the ect part which was not in the code. Totally missed the space.
    Any priest or shaman must be presumed guilty until proved innocent.

  6. #6
    Why does this simple apple script generate an error?
    Mark FX's Avatar
    Member Since
    Aug 13, 2011
    Location
    West Sussex, UK
    Posts
    200
    Rep Power
    9
    There are also potentially further errors in the AppleScript, which I would of come to later had the poster replied.

    Namley that when reading defaults through a shell command, boolean values are returned as integers of 0 and 1, which then have to be checked for, and converted to AppleScript true or false booleans, or converted to Yes or No string values, whichever would suit any other code in the script.

    Mark

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Help with a simple script
    By dgcrane in forum macOS - Development and Darwin
    Replies: 7
    Last Post: 07-11-2013, 10:16 PM
  2. Shortcut or simple script help needed
    By martinielsen in forum macOS - Operating System
    Replies: 6
    Last Post: 07-24-2012, 07:18 PM
  3. Help with simple Automator file copy script
    By PBear in forum macOS - Apps and Games
    Replies: 0
    Last Post: 04-20-2012, 10:09 PM
  4. Simple rsync script advice, please
    By Seventh in forum macOS - Operating System
    Replies: 0
    Last Post: 07-29-2011, 04:05 PM
  5. Automator and Apple script error handling
    By BjZ in forum macOS - Operating System
    Replies: 1
    Last Post: 01-02-2010, 12:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •