2016-04-09 5 views
0

学生の作業を整理するときに少しでも簡単にしたいと思います。私はAutomator/Applescriptで正しいワークフローを考え出すのに苦労しています。CSVの値としてPDFと名前をコピーしてフォルダを作成します

CSVリスト:

  • 学生A
  • 学生B
  • 学生C

PDFファイル:MarkScheme.pdf

相続人は私が望むものを起こる:

  1. という名前の 'MarkScheme-StudentA'

に、各フォルダに 'StudentA'

  • コピーPDFファイルとして名前、CSVファイルで最後のフォルダ(用を各学生のためのフォルダを作成します。各生徒)は次のようになります。

     
    - StudentA 
    -- MarkScheme-StudentA.pdf 
    - StudentB 
    -- MarkScheme-StudentB.pdf 
    - StudentC 
    -- MarkScheme-StudentC.pdf 
    
    

    これを達成する最もよい方法は何ですか。どうもありがとう。

  • 答えて

    1

    Applescriptのベローは、あなたが望むことをします。

    私はそれを明確にするためにいくつかのコメントを追加しました:そんなに

    set FCsv to choose file with prompt "Select your CSV file with students" 
    set Dest to choose folder with prompt "Select master folder" 
    set FPDF to choose file with prompt "Select your PDF file" 
    tell application "Finder" to set PdfName to name of FPDF 
    set PdfName to text 1 thru ((offset of ".pdf" in PdfName) - 1) of PdfName -- get PDF name without .pdf extension 
    
    set Fcontent to read FCsv -- read all cvs file 
    set FLines to every paragraph of Fcontent 
    repeat with aStudent in FLines -- loop through each line of the cvs file 
    tell application "Finder" 
        try -- try to create folder Student in master folder : assumption, it does not exist before ! 
         set SubFolder to make new folder in Dest with properties {name:aStudent} 
        end try 
        set SFolder to SubFolder as string 
        -- use 'cp' shell command to copy with new name 
        do shell script "cp " & (quoted form of (POSIX path of FPDF)) & " " & (quoted form of ((POSIX path of SFolder) & PdfName & "-" & aStudent & ".pdf")) 
    end tell 
    end repeat 
    
    +0

    感謝を。私が必要とするように正確に動作します! –

    関連する問題